Google App Engine: HTTP 错误 403: 禁止访问
我正在使用Google Books API来和我正在开发的电子商务网站进行整合。我的想法是让用户通过搜索框搜索书籍,然后调用Google的API来输出与搜索关键词对应的书籍数量。
但是,当我在表单中输入查询后点击提交时,出现了403 Forbidden错误。这很奇怪,因为在我本地测试应用时从来没有发生过这种情况。以下是我应用的代码:
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>
现在,jsony.html
还没有完成。我现在所做的只是显示包含输出的json的URL,还是原始的、未经处理的形式。
那么,是什么导致我在部署应用后出现这个403错误呢?
编辑 1:
当我从我的主Python文件中删除以下一行时,问题就解决了:
f = urllib2.urlopen(finaal).read()
但是,我需要我的API的URL来从其源代码中提取数据。到底发生了什么呢?
1 个回答
1
试着在网址后面加上 &country=US
这个参数。