[英]Google App Engine: HTTP Error 403: Forbidden
我正在使用Google Books API與正在開發的電子商務網站集成。 這個想法是讓用戶使用搜索欄搜索書籍,然后調用Google API以輸出與搜索關鍵字相對應的書籍數量。
但是,在表單中輸入查詢后單擊提交后,出現403禁止錯誤。 這很奇怪,因為這在我在本地主機上測試應用程序時從未發生過。 這是我的應用程序的代碼:
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才能從其源代碼中提取數據。 發生了什么 ?
嘗試將&country=US
添加到URL查詢字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.