Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to query Cloudflare via Python #542

Open
tiredofit opened this issue Aug 24, 2020 · 1 comment
Open

Unable to query Cloudflare via Python #542

tiredofit opened this issue Aug 24, 2020 · 1 comment

Comments

@tiredofit
Copy link

Hi there,
I've just tried to utilize the example in the examples folder for getting a list of records from cloudflare.

The following code

#!/usr/bin/python3

from lexicon.config import ConfigResolver
from lexicon.client import Client

lexicon_config = {
    "provider_name" : "cloudflare", # lexicon shortname for provider, see providers directory for available proviers
    "action": "list", # create, list, update, delete
    "domain": "example.com", # domain name
    "type": "CNAME", # specify a type for record filtering, case sensitive in some cases.
    "cloudflare": {
            "auth-token": "12345678",
            "auth-username": "example@example.com",
    }
}

config = ConfigResolver()
config.with_env().with_dict(dict_object=lexicon_config)               
client = Client(config)
results = client.execute()
print (results)

throws:

Traceback (most recent call last):
  File "./fuck", line 20, in <module>
    results = client.execute()
  File "/usr/lib/python3.8/site-packages/lexicon/client.py", line 81, in execute
    self.provider.authenticate()
  File "/usr/lib/python3.8/site-packages/lexicon/providers/base.py", line 74, in authenticate
    return self._authenticate()
  File "/usr/lib/python3.8/site-packages/lexicon/providers/cloudflare.py", line 52, in _authenticate
    payload = self._get("/zones", {"name": self.domain, "status": "active"})
  File "/usr/lib/python3.8/site-packages/lexicon/providers/base.py", line 159, in _get
    return self._request("GET", url, query_params=query_params)
  File "/usr/lib/python3.8/site-packages/lexicon/providers/cloudflare.py", line 204, in _request
    response.raise_for_status()
  File "/usr/lib/python3.8/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.cloudflare.com/client/v4/zones?name=example.com&status=active

Yet when I use the CLI

lexicon cloudflare --log_level DEBUG --auth-username example@example.com --auth-token 12345678 list example.com CNAME

It provides the list as expected. Can you advise what I may be missing?

@versi786
Copy link

versi786 commented Dec 5, 2020

If you are using an API Token you do not need to provide a username according to the documentation here. For example I solved his by only using the environment variable LEXICON_CLOUDFLARE_AUTH_TOKEN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants