如何在 Python Cloudflare API 中使用 Cloudflare API 密钥而不是令牌
问题:
你想使用 Cloudflare Python API 像这样访问 Cloudflare:
cloudflare_example_init.py
#!/usr/bin/env python3
import CloudFlare
cf = CloudFlare.CloudFlare(
email="[email protected]",
token="Oochee3_aucho0aiTahc8caVuak6Que_N_Aegi9o"
)
# ...但当你尝试像这样使用 key=... 参数时:
cloudflare_init_with_key_example.py
cf = CloudFlare.CloudFlare(
email="[email protected]",
key="Oochee3_aucho0aiTahc8caVuak6Que_N_Aegi9o"
)你看到此错误消息:
cloudflare_key_error.txt
Traceback (most recent call last):
File "run.py", line 4, in <module>
cf = CloudFlare.CloudFlare(
TypeError: __init__() got an unexpected keyword argument 'key'解决方案
只需像这样在 token=... 参数中使用密钥:
cloudflare_token_example.py
cf = CloudFlare.CloudFlare(
email="[email protected]",
token="[YOUR API KEY]"
)此用法在 Cloudflare API 的 README 部分中有官方文档。
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