Search code examples
pythonpython-3.xelasticsearchelasticsearch-py

Instantiating an Elasticsearch client fails only when using python3


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?


Solution

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