簡體   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