Unable to authenticate request through Cloudflare Python Module

I am following Cloudflare documentation for the first time to get DNS records inside of DNS Zones: https://developers.cloudflare.com/api/python/resources/dns/subresources/records/methods/list/ As a start I have installed cloudflare Python Module (4.0.0), but when I try to run that script given on Cloudflare API documentation, it gives me an error, and I really don’t know what can be, since I have been using ‘requests’ with cloudflare queries with an API Key that has real-only for all permissions (set on my account), and have been able to get data, but with that python module I am getting: cloudflare.BadRequestError: Error code: 400 - {‘success’: False, ‘errors’: [{‘code’: 10001, ‘message’: ‘Unable to authenticate request’}]} This is the code I am using: from cloudflare import Cloudflare ZONE_ID = ‘XXXX’ CLOUDFLARE_EMAIL = ‘XXXX’ CLOUDFLARE_API_KEY = ‘XXXX’ client = Cloudflare( api_email=CLOUDFLARE_EMAIL api_key=CLOUDFLARE_API_KEY ) page = client.dns.records.list( zone_id=ZONE_ID, ) page = page.result[0] print(page) Have also tried with just user_service_key inside of client, taking into account that was using just an API KEY to auth before over the other method, but got the same error. I am trying to use this python module because it will be a lot more easier for me to work with. I am felling a bit lost here … anyone here know what can be? or had the same issue?
Cloudflare API | DNS › Records › list
Interact with Cloudflare's products and services via the Cloudflare API
2 Replies
marafado88
marafado88OP2w ago
If I try to curl that URL I receive the same error: https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/dns_records ok regarding curl the issue was the type of authentication that I should have set to Bearer with the key, but not sure how to do that on python cloudflare module
Cyb3r-Jak3
Cyb3r-Jak32w ago
It would be api_token=<your token> and email is not needed

Did you find this page helpful?