Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using the code #1

Open
austinpowers opened this issue Aug 27, 2013 · 2 comments
Open

Error using the code #1

austinpowers opened this issue Aug 27, 2013 · 2 comments

Comments

@austinpowers
Copy link

Hi,
I am new user to python and I am apologizing before hand if my question is stupid but would love to learn what I am doing wrong. Thanks so much

I downloaded and installed the module but when I run the code, I get the error below

r = bingsearch.request("Python Software Foundation")

TypeError Traceback (most recent call last)
in ()
----> 1 r = bingsearch.request("Python Software Foundation")

C:\Users\Documents\Python Scripts\bingsearch.py in request(query, *_params)
6 def request(query, *_params):
7 r = requests.get(URL % {'query': query}, auth=('', API_KEY))
----> 8 return r.json['d']['results']

TypeError: 'NoneType' object has no attribute 'getitem'

@gimbel0893
Copy link

Seems there is a problem with the code. Maybe the Bing API has changed. Anyways, fix...

This is bingsearch.py, this is what it should be instead:

import urllib2
import requests

#URL = 'https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%(query)s&$top=50&$format=json'
URL = "https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%(source)s&Query=%(query)s&$top=50&$format=json"
API_KEY = 'SECRET_API_KEY'

def request(query, **params):
url = URL % {'source': urllib2.quote("'web'"),
'query': urllib2.quote("'"+query+"'")}
r = requests.get(url, auth=('', API_KEY))
return r.json()['d']['results']

And your first result will be in:
r = bingsearch.request("Python Software Foundation")
print r[0]['Web'][0]['Description']

@austinpowers
Copy link
Author

Awesome, thanks for replying! Appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants