Python Requests:requests.get(url).json()错误

时间:2019-04-01 21:06:43

标签: python json flask python-requests

当尝试使用python请求时,我获得以下信息:当我尝试确保请求为json格式时。使用//Reading the file contents into a text $yourJSON = file_get_contents('myfile.txt'); //Decode your JSON into a variable, assuming it will be an array $yourArray = json_decode($yourJSON); //Adding $_POST to the array $yourArray[]=$_POST; //Encode json_encode($_POST, JSON_PRETTY_PRINT); 时的请求为requests.get(url)

但是当使用<Response [200]>时,我得到以下信息:

request.get(url).json()

打印 File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 。header会给出以下内容:

requests.get(url)

我曾尝试剪切某些字符,例如<,>,\,\ 0,但这并没有影响结果。

1 个答案:

答案 0 :(得分:0)

以下请求应能工作。

import requests requests.get(URL, headers={'content-type':'application/json'}).json()