2

I'm using Google Books API to integrate with an E-commerce site that I'm developing. The idea is to let the users search for books using a search bar, and then calling the Google API to output the number of books corresponding to the search keyword.

However, I get a 403 Forbidden error after I click submit after entering my query in the form. This is strange, because this never happened when I was testing my application on the localhost. Here's the code for my application:

main.py

class SearchHandler(Handler): def get(self): self.render("search.html") def post(self): keey = self.request.get('keey') finaal = "https://www.googleapis.com/books/v1/volumes?q=" + keey + "&key=MY_APP_KEY" f = urllib2.urlopen(finaal).read() self.render("jsony.html", finaal = finaal) app = webapp2.WSGIApplication(('/search', SearchHandler)], debug=True) 

search.html

<html> <head> <title>Web Mining</title> </head> <body> <form method = "post"> Book Name:<input type = "text" name = "keey"> <input type = "submit"> </form> </body> </html> 

jsony.html

<html> <head> <title>Web Mining</title> </head> <body> <form method = "post"> {{finaal}} </form> </body> 

Now, the jsony.html is still incomplete. All I'm doing now is displaying the URL which contains the outputted json in it's raw, unprocessed form.

What seems to be causing this 403 error to arise after I deploy my application ?

EDIT 1:

The problem resolves when I remove the following line from my main python file:

f = urllib2.urlopen(finaal).read() 

However, I would be needing my API's URL in order to extract data from its source code. What's happening ?

7
  • Did you go to https://console.developers.google.com/project/apps~YOUR-APP/apiui/api and turn on the Books API? Commented Aug 20, 2014 at 1:44
  • Yes I did. Still, the same error. Commented Aug 20, 2014 at 3:19
  • As a separate issue, you never use the f = .... You are just sending the finaal string to the template. Are you sure you have the right key? try going directly to that url in your browser. Commented Aug 20, 2014 at 4:27
  • Yes, I can access the JSON format by directly accessing the link on my browser. It seems that Google Books API is forbidding me to access their page when I send them a request. Commented Aug 20, 2014 at 4:31
  • log finaal just before you try to urlopen it, to make sure it is what you think it is Commented Aug 20, 2014 at 4:36

1 Answer 1

1

Try adding &country=US to the URL query string.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.