App Engine 搜索 API - 短暂错误
我在使用App Engine的全文搜索API时遇到了一个问题,它总是抛出一个叫TransientError
的错误。我尽量把问题简化到最简单的形式(在生产服务器上还是会出现这个错误,但在开发环境下没有)。需要注意的是,这个问题出现在我所有的5个搜索索引上,不只是这一项。
from google.appengine.api import search
query_obj = search.Query(query_string='')
print search.Index(name='donation').search(query=query_obj)
这是App Engine给出的错误信息:
File "/base/data/home/apps/s~ghidonations/4e.365801633107307526/GlobalUtilities.py", line 914, in search
search_results = search.Index(name=index_name).search(query=query_obj)
File "/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 3093, in search
raise _ToSearchError(e)
TransientError
在我写这段文字的时候,有些搜索查询又开始正常工作了(之前5分钟前还报错),但有些还是不太对劲。我在之前的论坛上看到有人提到按日期排序(我在实际的生产代码中也是这么做的),所以我想把这个功能去掉可能会解决问题。但结果并没有解决——请看上面的3行代码。
有没有人知道这是什么原因呢?
1 个回答
3
临时错误是指那些将来会消失的错误。我不知道这些错误的具体原因,但谷歌建议你可以尝试重新搜索。
# Index the document.
try:
index.put(doc)
except search.PutError, e:
result = e.results[0]
if result.code == search.OperationResult.TRANSIENT_ERROR:
# possibly retry indexing result.object_id
except search.Error, e:
# possibly log the failure
这个例子来自于Index.put的文档,但在搜索API中我找不到其他关于临时错误的例子,所以我想你可能也能用同样的方法。
来源 https://developers.google.com/appengine/docs/python/search/indexclass#Introduction