post请求传了headers,报错
来源:9-2 模拟登录获取cookie请求订单接口

慕粉0820479194
2018-04-20
import json
import requests
import sys
class runmethod:
def requestmethod(self,url,data,headers):
res = requests.post(url=url,data=data,headers=headers).json()
return res
if __name__=='__main__':
res1 = runmethod()
url1 = 'http://uc.test.xbniao.com//v1.0/user/login'
data1 = {
"key": "388cafd957a13f27666d606cbb62bd4a",
"uname": "dandan",
"keep": 'true'
}
headers1 = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.9',
'Content-Length':'71',
'Content-Type':'application/json;charset=UTF-8',
'Cookie':'_xid=2e91257ac53d4802957196d9132468f9',
'Host':'uc.test.xbniao.com',
'Origin':'http://products.test.xbniao.com',
'X-APP-Code':'1012',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}
res = res1.requestmethod(url1,data1,headers1)
print(res)
运行后:{'errMsg': '请求参数格式错误(json)', 'statusCode': '2010001'}
1回答
-
Mushishi
2018-04-21
你好,程序没错,但是你看他接口接受你的请求后,返回的结果是说你请求参数格式错误,那么说明你请求参数并没有达到他服务端设置的格式要求,那你可以检查你headers里面的参数是否正确。
00
相似问题