2 回答

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'}
添加回答
舉報