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?

Adriano Todaro
  • 321
  • 1
  • 4
  • 14
  • Which version of the elasticsearch module are you using in each case? – John Zwinck May 09 '17 at 05:26
  • This might help: https://access.redhat.com/articles/2039753 – Val May 09 '17 at 05: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`? – Adonis May 09 '17 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. – Adonis May 10 '17 at 11:21

1 Answers1

7

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

Honza Král
  • 2,982
  • 14
  • 11