为什么我的 post 请求得到的是 return 代码 200 而不是 201? (Python /Requests/Json)
Why did I get return code 200 instead of 201 on my post request ? (Python /Requests/Json)
我正在使用 pandas 并请求创建一个 post 请求,而我正在创建的请求向我发送了状态代码 200 而不是 201。
在此 post 中,我从数据帧发送 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" 和 header 中的标记之间添加一个 space。
在我上面的示例中,您应该这样做:
api_call_headers = {'content-type':'application/json', 'accept':'application/json','authorization': 'Bearer ' + token}
我正在使用 pandas 并请求创建一个 post 请求,而我正在创建的请求向我发送了状态代码 200 而不是 201。
在此 post 中,我从数据帧发送 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" 和 header 中的标记之间添加一个 space。
在我上面的示例中,您应该这样做:
api_call_headers = {'content-type':'application/json', 'accept':'application/json','authorization': 'Bearer ' + token}