Answer the question
In order to leave comments, you need to log in
How to properly handle the exception?
Good afternoon.
How to properly handle an exception in python 3 and the elasticsearch module when the server is unavailable?
For example:
...
es = Elasticsearch(elastic_servers, http_auth=(elastic_user, elastic_password))
res = es.search(index=indices, body=query)
...
Answer the question
In order to leave comments, you need to log in
try:
es = Elasticsearch(elastic_servers, http_auth=(elastic_user, elastic_password))
res = es.search(index=indices, body=quer
except Exception as exc:
print('ALARM!', exc.args)
from traceback import format_exc
...
try:
es = Elasticsearch(elastic_servers, http_auth=(elastic_user, elastic_password))
res = es.search(index=indices, body=quer
except:
print('ALARM!')
print(format_exc(10)) # 10 - глубина стека
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question