3

I am hosting standalone elasticsearch on external server. Using certificate and login-password authentication. I am able to connect to it using browser or postman.

However when I try to do it, using python client it doesn't work. My connection code:

        self.es = Elasticsearch(
            address,
            ca_certs=cert_path,
            basic_auth=(user, password),
        )

Error message:

elastic_transport.TlsError: TLS error caused by: TlsError(TLS error caused by: SSLError(hostname '34.116.***.***' doesn't match either of 'localhost', '172.19.0.2', '127.0.0.1', 'bde723133f75'))

2 Answers 2

-1

Please try creating an ssl_context object and set the verification mode on the context.

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)

or you can try with this:

from ssl import create_default_context
from elasticsearch import Elasticsearch
es = Elasticsearch(["https://username:password@yourserver:9200"], verify_certs=False)
es.cat.nodes()

Option 2 will be warning, because it disable SSL with link url using HTTPS, but it work.

Sign up to request clarification or add additional context in comments.

2 Comments

I think there is some mistakes in your answer. Mainly elasticsearch does not have connection module. However I tried to do it from ssl import create_default_context using this. But it did not work
Hi @MichałBogusz, can you try with this: from ssl import create_default_context from elasticsearch import Elasticsearch es = Elasticsearch(["https://username:password@yourserver:9200"], verify_certs=False) es.cat.nodes()
-1

Using some help from Luc answer: Just before i tried something like this:

from ssl import create_default_context
import ssl
        context = create_default_context(capath=cert_path)
        context.check_hostname = False
        context.verify_mode = ssl.CERT_NONE
        self.es = Elasticsearch(
            address,
            ssl_context=context,
            basic_auth=(user, password),
            verify_certs=False,
        )

I am getting some warnings but other then that it works

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.