【发布时间】:2022-12-09 19:57:37
【问题描述】:
我一直在使用以下命令通过 curl 访问 supportpal API。 (https://docs.supportpal.com/current/REST+API)
curl.exe -i -u 'APIKEY:x' -X GET https://support.url.org/api/user/user/3697
这正确地抓取了数据。我试图用 python 复制它,但我不断遇到身份验证问题并收到以下错误。
Failed to authenticate because of bad credentials or an invalid authorization header
我使用的代码很简单。
import requests
import json
url = "https://support.url.org/api/user/user/3697"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer: {APIKEY:x}"
}
response = requests.request("GET", url, headers=headers)
print(response. Text)
我在想我的 auth 标头有问题,但无法弄清楚。
【问题讨论】:
标签: python api python-requests