python - Bingsearch returning 'instancemethod' object has no attribute '__getitem__' -


i have written code;

import bingsearch bingsearch.api_key='mykey' r = bingsearch.request("johndalton") r.status_code r[0]['description'] print r[0]['url'] 

this th bingsearch.py file

import requests import urllib2  url = 'https://api.datamarket.azure.com/data.ashx/bing/searchweb/web?query=%(query)s&$top=50&$format=json' api_key = 'mykey'  def request(query, **params):     r = requests.get(url % {'query': query}, auth=('', api_key))     return r.json['d']['results']    

as mentioned in title gives me instancemethod error. how should fix this?

@chris barker spot on earlier.

you need change line return r.json['d']['results'] return r.json()['d']['results'].

you should proper error checking on requests.get result , on json returned. might not contain items expect , raise keyerror.

for request errors might want check request documentation has basic starting points possible exceptions.


Comments

Popular posts from this blog

Need help in packaging app using TideSDK on Windows -

java - Why does my date parsing return a weird date? -