我收到此错误,但不知道问题出在哪里:
Traceback (most recent call last):
File "C:/Python34/Scripts/ddg.py", line 8, in <module>
data = json.loads(r)
File "C:\Python34\lib\json\__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'Response'
这是我的代码:
import requests, json
search_q = input('Enter query: ')
r = requests.get('https://api.duckduckgo.com/?q=%s&format=json&pretty=1' % search_q)
if r.status_code == requests.codes.ok:
data = json.loads(r)
node = data['RelatedTopics']['Result']
print (str(node))
else:
bad_r.raise_for_status()
最佳答案
无需手动加载 JSON;响应有 json
方法。
data = r.json()
关于python - 类型错误 : the JSON object must be str, 不是 'Response' 与 Python 3.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35291021/