我发送的帖子请求包含以下数据:
data = '{"email":"abc@gmail.com","password":"abcdef"}'
response = requests.post(login, data=data, headers={"Content-Type":"application/json"})
dataa = json.loads(response.content)
print dataa
token = dataa['token']
print "Access_token", token
headers = {"Content-Type":"application/json","Authorization":token}
data ='{"form":{"projectLocations":"LOPP","status":"Active","active":true,"name":"AWS","contactName":"xyz",
"contactEmail":"stu@gmail.com","customId":"102","createdCompany":"57972dcad9562e661c73707"}}'
res = requests.post(create_project, data=data, headers={"Content-Type":"application/json"})
dataa = json.loads(res)
print res
作为回报,我收到了以下回复:
dataa = json.loads(res)
File "C:\Python27\lib\json\__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
答案 0 :(得分:1)
第一次将响应内容用作loads
参数(dataa = json.loads(response.content)
),而第二次将响应对象用作loads
参数(dataa = json.loads(res)
)
所以尝试替换
dataa = json.loads(res)
带
dataa = json.loads(res.content)