2

I've been trying to use python's elasticsearch library to connect to my ElasticSearch host machine. So the code looks like:

client = Elasticsearch(
        ["https://my-machine.io:9200"],
        http_auth=("user", "password")
    )

Now the problem is that this instruction is only working when I use the python 2.7 interpreter, while it fails with python 3.6, generating the following error:

File "/usr/local/lib/python3.6/site-packages/elasticsearch/client/__init__.py", line 171, in __init__
    self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/transport.py", line 108, in __init__
    self.set_connections(hosts)
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/transport.py", line 163, in set_connections
    connections = list(zip(connections, hosts))
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/transport.py", line 160, in _create_connection
    return self.connection_class(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 78, in __init__
    raise ImproperlyConfigured("Root certificates are missing for certificate "
elasticsearch.exceptions.ImproperlyConfigured: Root certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically.

Python versions:

$ python2 --version
Python 2.7.13
$ python3 --version
Python 3.6.1

In both cases I'm using the "elasticsearch" package, version 5.3.0

I've not been able to find any piece of documentation that would suggest a different behaviour based on the version of python being used. Could anyone explain why is this happening?

4
  • Which version of the elasticsearch module are you using in each case? Commented May 9, 2017 at 5:26
  • This might help: access.redhat.com/articles/2039753 Commented May 9, 2017 at 5:53
  • Which version of python 2 did it work with? (because urllib's default mechanism is now to check the certificates by default). When instantiating your client, have you tried using the argument verify_certs=False? Commented May 9, 2017 at 13:45
  • In the site-packages of your python2, in elasticsearch/connection/http_urllib3.py, do you have a line if verify_certs? As that's the only change I can see that would raise this exception. Commented May 10, 2017 at 11:21

1 Answer 1

7

It looks like the problem is in your ssl setup, make sure you have certifi installed which will provide the root certificates needed.

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

1 Comment

certifi is a python package, pip install certifi, pypi.org/project/certifi

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.