使用需要不记名令牌的 API 在 Python 中进行 API 调用
寻求将 JSON API 调用集成到 Python 程序的帮助.
Looking for some help with integrating a JSON API call into a Python program.
我希望将以下 API 集成到 Python .py 程序中,以允许调用它并打印响应.
I am looking to integrate the following API into a Python .py program to allow it to be called and the response to be printed.
API 指南指出,必须生成不记名令牌以允许调用 API,我已经成功地做到了这一点.但是,我不确定在 Python API 请求中包含此令牌作为不记名令牌身份验证的语法.
The API guidance states that a bearer token must be generated to allow calls to the API, which I have done successfully. However I am unsure of the syntax to include this token as bearer token authentication in Python API request.
我可以使用包含令牌的 cURL 成功完成上述请求.我尝试过urllib"和requests"路由,但无济于事.
I can successfully complete the above request using cURL with a token included. I have tried "urllib" and "requests" routes but to no avail.
完整的 API 详细信息:IBM X-Force Exchange API 文档 - IP 声誉
Full API details: IBM X-Force Exchange API Documentation - IP Reputation
这只是意味着它希望它作为标题数据中的一个键
It just means it expects that as a key in your header data
import requests
endpoint = ".../api/ip"
data = {"ip": "1.1.2.3"}
headers = {"Authorization": "Bearer MYREALLYLONGTOKENIGOT"}
print(requests.post(endpoint, data=data, headers=headers).json())