Python 无法从http请求获取json响应

Python 无法从http请求获取json响应,python,http,https,python-requests,Python,Http,Https,Python Requests,我正在尝试使用requests模块获取JSON响应。我想知道是否有人知道这是什么原因 import requests url = "https://www.google.com/" data = requests.get(url) data.json() 错误: 从None引发JSONDecodeError(“预期值”,s,err.value) json.decoder.JSONDecodeError:预期值:第1行第1列(字符 0) 您返回的页面不是json,它的html来自: 如果J

我正在尝试使用requests模块获取JSON响应。我想知道是否有人知道这是什么原因

import requests

url = "https://www.google.com/"

data = requests.get(url)

data.json()
错误:

从None引发JSONDecodeError(“预期值”,s,err.value) json.decoder.JSONDecodeError:预期值:第1行第1列(字符 0)


您返回的页面不是json,它的html来自:

如果JSON解码失败,r.JSON()将引发异常。对于 例如,如果响应获得204(无内容),或者如果响应 包含无效的JSON,尝试r.JSON()将引发ValueError:无JSON 对象可以被解码

您需要有一个
url
,它可能返回一个
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'}