Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set verify_certs=False yet elasticsearch.Elasticsearch throws SSL error for certificate verify failed

self.host="KibanaProxy"

self.Port="443"

self.user="test"

self.password="test"

I need to suppress certificate validation. It works with curl when using option -k on command line. But while connecting using elasticsearch.Elasticsearch from Elasticsearch python module, it throws error.

_es2 = Elasticsearch([self.host], port=self.port, scheme="https", http_auth=(self.user, self.password), use_ssl=True, verify_certs=False)

_es2.info()

Error:

    raise SSLError('N/A', str(e), e)
elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED] 
certificate verify failed (_ssl.c:590)) caused by: SSLError([SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590))```
like image 475
sonali srivastava Avatar asked Dec 13 '22 13:12

sonali srivastava


1 Answers

Found it. While reading this post https://github.com/elastic/elasticsearch-py/issues/275, i got to know about connection_class. Looked for some standard or predefined method related to it so found https://elasticsearch-py.readthedocs.io/en/master/transports.html

Solution:

from elasticsearch import RequestsHttpConnection

.....

_es2 = Elasticsearch([self.host], port=self.port, connection_class=RequestsHttpConnection, http_auth=(self.user, self.password), use_ssl=True, verify_certs=False)

print(es.ping())

$ ./sn.py

True

like image 147
sonali srivastava Avatar answered Jan 05 '23 00:01

sonali srivastava