2017-02-22 200 views
0

所以我对web dev很陌生,所以对我一无所知。我已经订阅这给了我一个授权令牌的API和下面的curl命令:将curl命令转换为python获取请求

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer 37d5a9ac5442ba9f594a8ca1421a27b" "https://blah/blah/blah" 

这卷曲工作在终端,当我运行它返回一些JSON。现在我需要使用返回的json,所以我想要在JS或python中执行此请求。这里是我的Python的尝试:

url = "https://blah/blah/blah" 
headers = { 
    "Accept": "application/json", 
    "Authentication": "Bearer 37d5a9ac5442ba9f594a8ca1421a27b" 
} 
response = requests.get(url, headers=headers) 
print(response.text) 

这与回应:

{"fault":{"code":900902,"message":"Missing Credentials","description":"Required OAuth credentials not provided. Make sure your API invocation call has a header: \"Authorization: Bearer ACCESS_TOKEN\""}} 

我在做什么错?我没有一个明确的用户名和密码,就像其他类似问题的答案一样。

+0

执行curl语句导致从服务器返回200 OK? – kkaosninja

+1

https://curl.trillworks.com/ –

+0

@kkaosninja curl语句打印预期的json,所以我假设状态代码是200. –

回答

2

错误消息表明您的请求需要包含名为Authorization的标头。

但是,您的Python代码片段中有一个标头名称为Authentication的请求。