亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法從 http 請求獲取 json 響應

無法從 http 請求獲取 json 響應

肥皂起泡泡 2022-01-11 16:05:36
我正在嘗試使用 requests 模塊獲取 JSON 響應。想知道是否有人知道可能導致這種情況的原因。import requestsurl = "https://www.google.com/"data = requests.get(url)data.json()錯誤:提高 JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
查看完整描述

2 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

從文檔:


如果 JSON 解碼失敗,r.json() 會引發異常。例如,如果響應得到 204(無內容),或者如果響應包含無效的 JSON,則嘗試 r.json() 會引發 ValueError: No JSON object could be decoded。


您需要一個url可能返回的 a json:


import requests


url = 'https://github.com/timeline.json'    

data = requests.get(url).json()    

print(data)

輸出:


{'message': 'Hello there, wayfaring stranger. If you’re reading this then you probably didn’t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.', 'documentation_url': 'https://developer.github.com/v3/activity/events/#list-public-events'}



查看完整回答
反對 回復 2022-01-11
?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

您返回的頁面不是 json,而是它的 html


查看完整回答
反對 回復 2022-01-11
  • 2 回答
  • 0 關注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號