-1

I am trying to run below script:

import urllib
import json as m_json
query = raw_input ( 'Query: ' )
query = urllib.urlencode ( { 'q' : query } )
response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
json = m_json.loads ( response )
results = json [ 'responseData' ] [ 'results' ]
for result in results:
    title = result['title']
    url = result['url']   # was URL in the original and that threw a name error exception
    print ( title + '; ' + url )

My output is:

Query: test
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    results = json [ 'responseData' ] [ 'results' ]
TypeError: 'NoneType' object has no attribute '__getitem__'
2
  • The Google Web Search API is no longer available. Please migrate to the Google Custom Search API Commented Apr 29, 2017 at 10:22
  • json['responseData'] is None. See here. Commented Apr 29, 2017 at 10:40

2 Answers 2

2

After printing out the raw json with the following code:

print(str(json))

we get the following response from google:

{'responseData': None, 'responseDetails': 'The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)', 'responseStatus': 403}

A solution can be found here:

What are the alternatives now that the Google web search API has been deprecated?

Sign up to request clarification or add additional context in comments.

Comments

0

You can print the result and you will see the following:

The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)

Try that ;) good luck

PS: For more info, you may like to visit this detailed tutorial in another stack overflow question

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.