0

I have written this code;

import bingsearch
bingsearch.API_KEY='mykey'
r = bingsearch.request("JohnDalton")
r.status_code
r[0]['Description']
print r[0]['Url']

This is 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 i mentioned in the title it gives me an instancemethod error. How should i fix this?

user2626758
  • 117
  • 1
  • 12

1 Answers1

1

@Chris Barker was spot on earlier.

You need to change your line return r.json['d']['results'] into return r.json()['d']['results'].

You should really do proper error checking on your requests.get result and on the JSON returned. It might not contain the items you expect and it will then raise a KeyError.

For the request errors you might want to check the request documentation which has some basic starting points for possible exceptions.

Wessie
  • 3,460
  • 2
  • 13
  • 17
  • Thanks. For that. Now i get an error 'JSONDecodeError: Expecting value: line 1 column 1 (char 0)'. I have never gotten this error. – user2626758 Aug 08 '13 at 16:48
  • @user2626758 it's an issue with the JSON you are passing to it, you should open a new question for this. – Wessie Aug 08 '13 at 20:05