1

我一直在尝试使用 python 的 elasticsearch 库连接到我的 ElasticSearch 主机。所以代码看起来像:

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

现在的问题是该指令仅在我使用 python 2.7 解释器时有效,而在 python 3.6 中它失败,产生以下错误:

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版本:

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

在这两种情况下,我都使用“elasticsearch”包,版本 5.3.0

我找不到任何可以根据所使用的 python 版本提出不同行为的文档。谁能解释为什么会这样?

4

1 回答 1

6

看起来问题出在您的 ssl 设置中,请确保您已certifi安装它将提供所需的根证书。

于 2017-05-09T14:20:55.247 回答