cloudflare-python icon indicating copy to clipboard operation
cloudflare-python copied to clipboard

Simple SDK Request to get DNS Records returns `Missing X-Auth-Key, X-Auth-Email or Authorization headers`

Open chakraborty29 opened this issue 3 months ago • 1 comments

Confirm this is a Python library issue and not an underlying Cloudflare API issue.

  • [x] This is an issue with the Python library

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

chakraborty29 avatar Nov 25 '25 17:11 chakraborty29

Adding in the api_email is what fixed it. See the final code below:

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')
API_EMAIL = os.environ.get('API_EMAIL')

def main():
    client = Cloudflare(
        api_email=API_EMAIL,
        api_token=CLOUDFLARE_API_KEY,
    )
    page = client.dns.records.list(
        zone_id=ZONE_ID,
    )
    page = page.result[0]
    print(page)


if __name__ == "__main__":
    main()

Can we make this more clear in the documentation? Happy to create a PR for this. Would appreciate some feedback from the cloudflare team.

chakraborty29 avatar Nov 25 '25 17:11 chakraborty29