为什么python请求返回401?



为什么这个python代码返回401请求状态码w

import requests
url = "https://localtonet.com/api/GetAuthTokens"
def send_request():
headers = {'accept': 'application/json',
'Authorization': 'Bearer h<REDACTED>E'}
resp = requests.get(url, headers=headers)
return resp
print (send_request())

官方文档声明请求应该类似于

curl -X 'GET' 
'https://localtonet.com/api/GetAuthTokens' 
-H 'accept: application/json' 
-H 'Authorization: Bearer h<REDACTED>E'

您的代码看起来不错。您只需要将<mytoken>替换为您必须通过向某些接口/API提供您的用户名和密码来获得的实际令牌。

HTTP状态码401表示Unauthorized,这基本上意味着您的授权凭证无效。

看看你想要访问的API,我在他们的网站上发现了这个:

您可以从https://localtonet.com/Dashboard获取ApiKey

尝试登录到仪表板,看看是否可以从那里获得令牌。

我希望这对你有帮助。

最新更新