繁体   English   中英

奇怪:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)

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

我正在使用Python 3.6.4,这是我的代码:

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)

然后我得到一个错误:期望值:第1行第1列(字符0)我仍在尝试查找错误的位置。 当我测试此行时:

dict_json = json.loads(json_response)

追溯是:

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)

我真的是python和json的新手。 尽管我尝试搜索Internet来解决我的问题,但最终还是失败了。

我上面提到的网页确实有一些汉字,但是我认为这不是问题。

在此处输入图片说明

有人可以帮忙吗?

此文本不是json格式。 只需进行一些更改以适合json格式,然后我就可以使用Json模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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