简体   繁体   English

Google App Engine:HTTP错误403:禁止

[英]Google App Engine: HTTP Error 403: Forbidden

I'm using Google Books API to integrate with an E-commerce site that I'm developing. 我正在使用Google Books API与正在开发的电子商务网站集成。 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. 这个想法是让用户使用搜索栏搜索书籍,然后调用Google API以输出与搜索关键字相对应的书籍数量。

However, I get a 403 Forbidden error after I click submit after entering my query in the form. 但是,在表单中输入查询后单击提交后,出现403禁止错误。 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 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 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 jsony.html

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

Now, the jsony.html is still incomplete. 现在, jsony.html仍然不完整。 All I'm doing now is displaying the URL which contains the outputted json in it's raw, unprocessed form. 我现在要做的只是以未处理的原始格式显示包含输出的json的URL。

What seems to be causing this 403 error to arise after I deploy my application ? 部署应用程序后,似乎是什么导致此403错误出现?

EDIT 1: 编辑1:

The problem resolves when I remove the following line from my main python file: 当我从主python文件中删除以下行时,该问题得以解决:

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

However, I would be needing my API's URL in order to extract data from its source code. 但是,我需要我的API的URL才能从其源代码中提取数据。 What's happening ? 发生了什么 ?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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