Python Elasticsearch报错

elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED] 
certificate verify failed: self signed certificate in certificate chain (_ssl.c:1076))
caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
self signed certificate in certificate chain (_ssl.c:1076))

解决

加上​​context.verify_mode = ssl.CERT_NONE​​:

import ssl
from elasticsearch.connection import create_ssl_context

ssl_context = create_ssl_context(<use `cafile`, or `cadata` or `capath` to set your CA or CAs)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

es = Elasticsearch('localhost', ssl_context=context, timeout=60

参考

​https://github.com/elastic/elasticsearch-py/issues/712​​​

https://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
https://github.com/certifi/python-certifi