0
我送與下面的數據POST請求的響應:我得到這個類型錯誤:預期的字符串或緩衝區,而試圖從服務器獲取
data = '{"email":"[email protected]","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":"[email protected]","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
你明白了什麼,當你做'打印res.text'? – DeepSpace
同樣的錯誤,當我打印res.text。 –
請務必在'dataa = json.loads(res)'上方放置'print res.text' **,否則您將看到相同的異常。 – DeepSpace