当使用Python、Flask、Heroku、Jquery和Google Books API处理small profect(日语)时,我在执行"検索“时遇到了500内部服务器错误,这意味着”搜索“。
当您在旁边的框中单击"検索“w/一些输入时,它会向Google Books API发送请求,并通过Ajax w/ Jquery获取与该参数匹配的图书数据,如下所示。
@app.route("/_search_books")
def search_books():
title = request.args.get('title')
if title:
title = title.encode('utf-8')
url = 'https://www.googleapis.com/books/v1/volumes?q=' + title
h = urlopen(url)
data = json.load(h)
books = []
for i in range(len(data['items'])):
try:
title = data['items'][i]['volumeInfo']['title']
except:
title = None
try:
author = data['items'][i]['volumeInfo']['authors'][0]
except:
author = None
try:
publisher = data['items'][i]['volumeInfo']['publisher']
except:
publisher = None
try:
year = data['items'][i]['volumeInfo']['publishedDate']
except:
year = None
try:
thumbnail = data['items'][i]['volumeInfo']['imageLinks']['thumbnail']
except:
thumbnail = None
try:
page = data['items'][i]['volumeInfo']['pageCount']
except:
page = None
books.append({'title': title, 'author': author, 'publisher': publisher, 'year': year, 'thumbnail': thumbnail, 'page': page})
return jsonify(result=books)它在开发中工作正常,所以我猜它是与Google Books API的权限相关的东西或与SSL相关的东西。
奇怪的是,它并不总是返回500,有时还会返回预期的结果。这似乎取决于我执行的时间,比如上午200次,下午500次。
提前感谢:)
发布于 2013-11-06 06:09:41
我也有同样的问题。我的在开发和生产之间没有什么不同;它们都只是偶尔返回500。消息是"Backend error“。我不相信你可以做任何事情来解决这个问题;这似乎是谷歌的一个问题。我通常可以在几秒钟后再次重复相同的查询,它工作得很好。
发布于 2020-01-17 10:54:57
嘿,我实际上也有同样的问题,将请求量更低的maxResults=15改为搜索字符串它修复了这个问题
https://stackoverflow.com/questions/19172184
复制相似问题