Python Django Elasticsearch环境中的SSL问题

cbeh67ev  于 2023-04-29  发布在  ElasticSearch
关注(0)|答案(1)|浏览(114)

我正在为一个Python Django项目运行一个本地的dockerised Elasticsearch示例,我是按照elastic docker guide设置的。
其中一个步骤涉及下载CA证书文件。当容器运行时,我可以使用这个证书文件连接到它,或者完全忽略证书

# both of these work
curl --cacert my_cert.crt "https://${ELASTIC_USERNAME}:${ELASTIC_PASSWORD}@localhost:9200"
curl -k "https://${ELASTIC_USERNAME}:${ELASTIC_PASSWORD}@localhost:9200"

然后,我将ELASTICSEARCH_DSN的详细信息添加到我的settings.py文件中,如elasticsearch dsl docs中所述,但文档中没有提到证书,运行命令会给出SSL错误:

python manage.py search_index --rebuild

<snip>
elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1002)) caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1002))

我不知道解决这件事的最好方法。任何建议将不胜感激。

8ehkhllq

8ehkhllq1#

想通了,很简单

ELASTICSEARCH_DSL = {
    "default": {
        "hosts": [
            f"https://{elastic_username}:{elastic_password}@{elastic_hostname}:{elastic_port}"
        ],
        "use_ssl": True,
        "ca_certs": "relative/path/to/http_ca.crt"
    }
}

相关文档

相关问题