Python Cloudflare CloudFlare.exceptions.CloudFlareAPIError: no email and no token defined beheben
English
Deutsch
Problem:
Ein Programm soll mit der Cloudflare-API ausgeführt werden, z.B. dieser Beispielcode:
cloudflare_no_creds.py
#!/usr/bin/env python3
import CloudFlare
cf = CloudFlare.CloudFlare()
zones = cf.zones.get()
for zone in zones:
zone_id = zone['id']
zone_name = zone['name']
print(zone_id, zone_name)Beim Versuch, es auszuführen, erscheint die folgende Fehlermeldung:
cloudflare_no_creds_traceback.txt
Traceback (most recent call last):
File "test-cloudflare-api.py", line 5, in <module>
zones = cf.zones.get()
File "/usr/local/lib/python3.8/dist-packages/CloudFlare/cloudflare.py", line 672, in get
return self._base.call_with_auth('GET', self._parts,
File "/usr/local/lib/python3.8/dist-packages/CloudFlare/cloudflare.py", line 117, in call_with_auth
self._AddAuthHeaders(headers, method)
File "/usr/local/lib/python3.8/dist-packages/CloudFlare/cloudflare.py", line 88, in _AddAuthHeaders
raise CloudFlareAPIError(0, 'no email and no token defined')
CloudFlare.exceptions.CloudFlareAPIError: no email and no token definedLösung
Der Cloudflare-API fehlen die Anmeldeinformationen. Die einfachste Methode, die API mit Anmeldeinformationen aufzurufen, besteht darin, CloudFlare.CloudFlare() mit E-Mail und Token als Argumente zu initialisieren.
cloudflare_creds_example.py
cf = CloudFlare.CloudFlare(
email="[email protected]",
token="Oochee3_aucho0aiTahc8caVuak6Que_N_Aegi9o"
)Beachten, dass nicht alle Operationen mit allen Tokens möglich sind und bei einer Operation, die mit dem Token nicht möglich ist, eine Fehlermeldung wie CloudFlare.exceptions.CloudFlareAPIError: Invalid request headers erscheint.
Check out similar posts by category:
Networking, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow