[英]Python Requests getting 401 error
Currently trying to request a json using python but I keep getting a 401 error on response. 目前尝试使用python请求json,但响应中却不断出现401错误。 When I use curl I receive the correct json data.
当我使用curl时,我会收到正确的json数据。
Curl I use: 我使用的卷发:
curl -H "X-Samanage-Authorization: Bearer API_TOKEN" -H 'Accept: application/vnd.samanage.v2.1+json' -H 'Content-Type: application/json' -X GET https://api.samanage.com/incidents.json
Python that results in 401 error: 导致401错误的Python:
import json
import requests
response = requests.get('https://api.samanage.com/incidents.json', headers={'X-Samanage-Authorization': 'API_TOKEN'})
print(response.status_code)
Depending on what you're trying to do, your problem is probably that you are not specifying the type of your credentials . 根据您要尝试执行的操作,您的问题可能是您未指定凭据的类型 。
Try doing : 尝试做:
import json
import requests
response = requests.get('https://api.samanage.com/incidents.json', headers={'X-Samanage-Authorization': 'Bearer ' + API_TOKEN})
print(response.status_code)
Another case, your API_TOKEN
is not the actual token if you have not made a mistake while typing your code back. 在另一种情况下,如果您在键入代码时没有犯错,则您的
API_TOKEN
不是实际的令牌。 You have a STRING API_TOKEN
, but not the actual token. 您有STRING
API_TOKEN
,但没有实际的令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.