Confirm this is a Python library issue and not an underlying Cloudflare API issue.
Describe the bug
I am just creating a simple client, with the Global API Key and ZoneID to get a list of my DNS records as per the docs: https://developers.cloudflare.com/api/python/resources/dns/subresources/records/methods/list/
However, it returns:
cloudflare.BadRequestError: Error code: 400 - {'success': False, 'errors': [{'code': 9106, 'message': 'Missing X-Auth-Key, X-Auth-Email or Authorization headers'}]}
I've used a both the Global API Key and a custom API Token, with no success. Not sure what I am missing from the documentation.
To Reproduce
Run the following code snippet:
import os
from dotenv import load_dotenv
from cloudflare import Cloudflare
load_dotenv()
CLOUDFLARE_API_KEY = os.environ.get('CLOUDFLARE_API_KEY')
ZONE_ID = os.environ.get('ZONE_ID')
def main():
client = Cloudflare(
api_token=CLOUDFLARE_API_KEY,
)
page = client.dns.records.list(
zone_id=ZONE_ID,
)
page = page.result[0]
print(page)
if __name__ == "__main__":
main()
OS
macOS
Python version
3.13.5
Library version
v4.3.1