简体   繁体   中英

weird: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I am using Python 3.6.4 and here is my code:

try:
    url1 = 'http://pdfm2.eastmoney.com/EM_UBG_PDTI_Fast/api/js?id=6012291&TYPE=k&js=fsData1520121867451((x))&rtntype=5&isCR=false&fsData1520121867451=fsData1520121867451'
    head = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4549.400 QQBrowser/9.7.12900.400'}
    page = requests.get(url1, headers=head)
    json_response = page.content.decode()
    dict_json = json.loads(json_response)
    print(page.text)

except Exception as e:
    print(e)

Then I got an error: Expecting value: line 1 column 1 (char 0) I am still trying to find where the error is. When I tested this line:

dict_json = json.loads(json_response)

the Traceback is:

Traceback (most recent call last):
  File "C:\Users\Xiao\AppData\Roaming\Python\Python36\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-73-4bee6474d695>", line 1, in <module>
    dict_json = json.loads(json_response)
  File "D:\python3-6-4\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "D:\python3-6-4\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\python3-6-4\lib\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)

I am really new to python and json. Although I have tried to search the Internet to solve my problem, but got failed at the end.

The webpage I mentioned above do have some Chinese characters, but I think that is not the problem.

在此处输入图片说明

Anybody can help?

This text is not json format. Just make some changes to fit json format and then I can use Json module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM