Here is my code:
import os
import sys
import time
from urllib import FancyURLopener
import urllib2
import simplejson
# Define search term
searchTerm = \"parrot\
The error message tells you that results['responseData'] == None
. You need to look at what you actually get in results
(e.g. print(results)
) to figure out how to access the data you want.
I get the following when your error occurs:
{u'responseData': None, # hence the error
u'responseDetails': u'out of range start', # what went wrong
u'responseStatus': 400} # http response code for "Bad request"
Eventually you load a url (i.e. https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=parrot&start=90&userip=MyIP
) where the search results simply don't go that high. I get a sensible content in results
for lower numbers: ...&start=0&...
.
You need to check whether you get anything back, e.g.:
if results["responseStatus"] == 200:
# response was OK, do your thing
Also, you could make your url-building code simpler and save on the string concatenation:
template = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q={}&start={}&userip=MyIP'
url = template.format(searchTerm, str(i * 10))