无法为 Web API 解码 JSON 个对象

No JSON object could be decoded for the web APIs

我是 python 的新手,我目前正在重复 "python for data analysis"

书中所有已解决的示例

在一个示例中,我需要从 Twitter 搜索访问 API。这是代码:

import requests
url='https://twitter.com/search?q=python%20pandas&src=typd'
resp=requests.get(url)

到目前为止一切正常。当我使用 json

时出现问题
import json
data=json.loads(resp.text)

然后我收到了错误信息ValueError: No JSON object could be decoded

我试图切换到另一个 url 而不是 twitter,但我仍然收到相同的错误消息。

有人有什么想法吗?谢谢

您需要包含 JSON 内容的回复。要搜索 Twitter,这需要使用 api.twitter.com,但您需要获得一个 OAuth 密钥。它比您拥有的 5 行代码更复杂。参见 http://nbviewer.ipython.org/github/chdoig/Mining-the-Social-Web-2nd-Edition/blob/master/ipynb/Chapter%201%20-%20Mining%20Twitter.ipynb