我正在尝试运行似乎是一个非常简单的扫描,但我遇到了一个奇怪的异常。似乎由扫描创建的生成器遇到了一个异常,我不知道为什么。我尝试在try/except中包装我的for循环的内部,但它仍然抛出异常,所以我猜它在击中es时死亡。如果你能帮我弄清楚是怎么回事,下面是我的资料:
old_stuff_query = {"query": {"filtered": {
"filter": {
"range": {
"expire_on": {'lte': datetime.datetime.now() - datetime.timedelta(weeks=53)}}
}}}}
scanResp = scan(client=es, query=old_stuff_query, scroll="1m", index="myIndex", doc_type="myDoc")
counter = 0
for resp in scanResp:
try:
print("YAH")
except:
print("BOO")
但是我得到以下内容:
for resp in scanResp:
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 314, in scan
client.clear_scroll(body={'scroll_id': [scroll_id]}, ignore=(404, ))
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 688, in clear_scroll
params=params, body=body)
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 327, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/connection/http_requests.py", line 84, in perform_request
self._raise_error(response.status_code, raw_data)
File "/home/will/.virtualenvs/side_project/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 113, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.AuthorizationException: <exception str() failed>
最令人沮丧的部分是这完全是随机发生的。在不到1万份文档和超过25万份文档后,它出现了错误。任何帮助都是很棒的,谢谢!
所以我也有同样的错误,并找到了原因:如果您使用特殊的 在你的情况下,它似乎是在api方面的草率编程。__str__
创建了自己的类,并且在此方法或其他被调用的方法中抛出了与它试图创建字符串的实例相关的错误,则错误消息将被替换为'