我正在使用 Pandas 和 requests 创建一个 post 请求,而我正在创建的那个向我发送了一个状态代码 200 而不是 201。
在这篇文章中,我从数据帧发送了一个 JSON。这部分似乎不错。不知道header好不好,里面改了很多东西,都没有成功。
这个问题没有显示任何错误,受请求影响的服务器也没有给出任何迹象。第一个请求给了我访问令牌并且运行良好。
def post_json(nbr_requests):
auth_json = {'grant_type': 'password', 'client_id': 'hidden','client_secret':'hidden','username':'hidden','password':'hidden'}
auth_response = requests.post('http://hidden:8080/lot/of/stufs/token',data=auth_json)
token = auth_response.json()["access_token"]
api_call_headers = {'content-type':'application/json', 'accept':'application/json','authorization': 'Bearer' + token}
url_to_go = "http://localhost:8080/hidden/link"
for i in range(nbr_requests):
api_call_response = requests.post(url_to_go, headers=api_call_headers, json=json_array_to_send[i],data={"key": "value"})
print (api_call_response.status_code)
我知道这个问题不清楚,但是如果有人遇到同样的问题,您应该在“Bearer”和标题中的令牌之间添加一个空格。
在我上面的例子中,你应该做这样的事情:
api_call_headers = {'content-type':'application/json', 'accept':'application/json','authorization': 'Bearer ' + token}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句