gpt4 book ai didi

python - 为什么弹性会引发此异常 "elasticsearch.exceptions.ConnectionError: ConnectionError(check_hostname requires server_hostname)"?

转载 作者:太空宇宙 更新时间:2023-11-03 14:23:00 25 4
gpt4 key购买 nike

我正在尝试从 python 脚本查询 elasticsearch,但出现异常。

我遵循了官方指南,例如 this one .但是当我试图查询 elasticsearch 时,没有成功。这里是异常(exception):

File "C:\...\connection\http_urllib3.py", line 250, in perform_request
raise ConnectionError("N/A", str(e), e)
elasticsearch.exceptions.ConnectionError:
ConnectionError(check_hostname requires server_hostname) caused by: ValueError(check_hostname requires server_hostname)

这是我的代码:

from elasticsearch import Elasticsearch
from elasticsearch import RequestsHttpConnection
from ssl import create_default_context
import ssl



context = create_default_context(cafile="certificate.pem")
es = Elasticsearch("https://localhost", ssl_context=context, http_auth=('username','password'))

res = es.search(index="dr_*", body = {
'size' : 10,
'query': {
'match_all' : {}
}
})

为什么会这样?

最佳答案

不幸的是,我也遇到了这样的问题。

默认情况下,context中check_hostname的值为True,所以你必须指定server_hostname。这是一个简单的解决方案,只需在创建上下文后添加以下行

context.check_hostname = False

它应该没有任何问题

关于python - 为什么弹性会引发此异常 "elasticsearch.exceptions.ConnectionError: ConnectionError(check_hostname requires server_hostname)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59068397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com