【python】【requests】调用requests库post时遇到Post call throwing HTTP 400 Bad Request

python在调用requests的post时,http server返回400 Bad Request error;

在post时,使用了resp=requests.post(url=URL,data=payload,headers=headers)

此时,tomcat返回结果为HTTP 400 Bad Request,即对应的请求实例对应的结构无法正常匹配,还没有正常到达后端服务,网上搜索出来的结果大多是java spring的处理结果,是将对应的结构体中的数据类型不匹配的问题,或者是data入参的名称不一致的问题;但这个无法解决我的问题,后来在stackoverflow上找到一个解决方案,能够解决我的问题,将请求中的data入参换做json,解决:resp=requests.post(url=URL,json=payload,headers=headers),其中payload、headers是dict,URL为string。

参考解决方案:https://stackoverflow.com/questions/32659134/python-post-call-throwing-400-bad-request

猜你喜欢

转载自blog.csdn.net/meteoryuyu/article/details/83146530