[Solved] TypeError: ‘NoneType’ object has no attribute ‘__getitem__’. Bing search [closed]


Your function doesn’t return anything. Printing is not the same thing as returning a value.

The default return value for a function is None, which causes your error. You want to return something, most likely r.json():

def request(query, **params):
    query = ('%27'+query+ '%27')
    r = requests.get(URL % {'query': query}, auth=('', API_KEY))
    return r.json()

then loop over the results:

r = request("JasonBourne")
for res in r['d']['results']:
    print res['Url']

or collect them all in a list with a list comprehension:

r = request("JasonBourne")
urls = [res['Url'] for res in r['d']['results']]

giving you a list urls.

8

solved TypeError: ‘NoneType’ object has no attribute ‘__getitem__’. Bing search [closed]