简体   繁体   中英

Google App Engine: HTTP Error 403: Forbidden

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 ?

尝试将&country=US添加到URL查询字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM