【发布时间】:2017-07-12 23:25:39
【问题描述】:
我订阅了一个 API,它给了我一个授权令牌和以下 curl 命令:
curl -X GET --header "Accept: application/json" --header "Authorization: Bearer 37d5a9ac5442ba9f594a8ca1421a27b" "https://blah/blah/blah"
这个 curl 在终端中工作,并在我运行它时返回一些 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\""}}
我做错了什么?我没有像其他类似问题的答案所暗示的那样明确的用户名和密码。
【问题讨论】:
-
执行 curl 语句导致服务器返回 200 OK?
-
@kkaosninja curl 语句打印了预期的 json,所以我假设状态码是 200。
-
@IanD 我相信 sideshowbarker 的回答应该可以解决您的问题 :-)