此错误已在很多线程中进行了讨论,在发布此问题之前,我尝试了所有这些方法!他们都没有解决我的问题,我继续遇到同样的错误。但是在浏览器中打开相同的URL时,它确实返回有效的json响应。仅在我的python代码中失败了。
这是我的代码,
url = 'https://<some-site-name>'
headers = {'some headers'}
payload = {'some payload'}
req = requests.post(url, data=payload, headers=headers)
print(req.json()) **-> errors appears on this line**
下面是详细的错误日志,
Traceback (most recent call last):
File "/home/ssh/testcode/kpp_login.py", line 142, in <module>
print(req.json())
File "/home/ssh/.local/lib/python2.7/site-packages/requests/models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "//home/ssh/.local/lib/python2.7/site-packages/simplejson /__init__.py", line 518, in loads
return _default_decoder.decode(s)
File "/home/ssh/.local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/home/ssh/.local/lib/python2.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)