I am trying to run below script:
import urllib
import json as m_json
query = raw_input ( 'Query: ' )
query = urllib.urlencode ( { 'q' : query } )
response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
json = m_json.loads ( response )
results = json [ 'responseData' ] [ 'results' ]
for result in results:
title = result['title']
url = result['url'] # was URL in the original and that threw a name error exception
print ( title + '; ' + url )
My output is:
Query: test
Traceback (most recent call last):
File "test.py", line 7, in <module>
results = json [ 'responseData' ] [ 'results' ]
TypeError: 'NoneType' object has no attribute '__getitem__'