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'}
添加回答
举报