I'm getting this error and I can't figure out what the problem is:
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'
This is my code:
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()
No need to load the JSON manually; the response has a json method.
data = r.json()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With