Skip to content

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

@chakraborty29

Description

@chakraborty29

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

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions