【问题标题】:weird: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)奇怪:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)
【发布时间】:2018-03-17 23:01:19
【问题描述】:

我使用的是 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 真的很陌生。虽然我尝试在互联网上搜索解决我的问题,但最终失败了。

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

有人可以帮忙吗?

【问题讨论】:

    标签: python json python-3.x


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 2020-11-11
      • 2017-05-09
      • 2019-08-13
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多