今天遇到个坑,简单记录一下!
res = {'a':1, 'b':2}
headers = {'content-type': 'application/json'}
resp = requests.post('http:/xxx/xxx', json=res, headers=headers)
上面这样写,就不会报错了。
---- 之前报错,总结 -------------------------------------
(1)有些要传header的,后端接口设置更多的,header就更复杂;
(2)之前把res_json = json.dumps()了,然后传参data=res_json, 后来发现不行,python调post不需要!比如报错的这一句: resp = requests.post('http:/xxx/xxx', data=res_json, headers=headers)