Python访问API-身份验证错误

iecba09b  于 2022-12-10  发布在  Python
关注(0)|答案(1)|浏览(118)

我已经通过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标题,但不能弄清楚它。

nxowjjhe

nxowjjhe1#

from requests.auth import HTTPBasicAuth
import requests

url = 'https://support.url.org/api/user/user/3697'
headers = {'Accept': 'application/json'}
auth = HTTPBasicAuth('apikey', x)

req = requests.get(url, headers=headers, auth=auth)

相关问题