【发布时间】:2017-09-11 15:49:32
【问题描述】:
当使用 curl 调用 API 时,它会返回响应,而当使用 python 中的 requests 库调用相同的 API 时,会产生错误:
卷发:
curl -X GET --header "Accept: application/json" --header "Authorization: oauth_code" "https://api.getgo.com/G2W/rest/organizers/5913931473742004748/historicalWebinars?fromTime=2017-07-13T10%3A00%3A00Z&toTime=2017-09-10T10%3A00%3A00Z"
请求代码:
import requests
import datetime
date_11_days_back = (datetime.datetime.now() - datetime.timedelta(days=11)).isoformat()
date_now = datetime.datetime.now().isoformat()
webinars_url = "https://api.getgo.com/G2W/rest/organizers/5913931473742004748/historicalWebinars"
params = {
'fromTime': date_11_days_back,
'toTime': date_now
}
headers = {
'Authorization': 'oauth_token'
}
last_week_webinars = requests.get(webinars_url, headers=headers, params=params)
此调用导致错误提示 b'{"errorCode":"InvalidRequest","description":"Your request could not be processed because one or more of the request parameters are an invalid type.","incident":"5308828452798993933"}'
我知道,这是 API 特有的。
如下传递headers也会产生错误:
headers = {
'Authorization': "TOK:{}".format(goto_webinar_access_token)
}
错误:b'{"int_err_code":"InvalidToken","msg":"Invalid token passed"}'
我想看看token 是作为http 调用的一部分发送的。怎么会这样。
【问题讨论】:
标签: python-3.x curl python-requests