Python “弹性”为什么提出这个例外;elasticsearch.exceptions.ConnectionError:ConnectionError(检查“主机名需要服务器”主机名)“;?
我试图从python脚本查询elasticsearch,但引发了一个异常 我遵循官方指南,如。 但当我试图查询elasticsearch时,没有成功。例外情况如下:Python “弹性”为什么提出这个例外;elasticsearch.exceptions.ConnectionError:ConnectionError(检查“主机名需要服务器”主机名)“;?,python,
elasticsearch,ssl,Python,
elasticsearch,Ssl,我试图从python脚本查询elasticsearch,但引发了一个异常 我遵循官方指南,如。 但当我试图查询elasticsearch时,没有成功。例外情况如下: File "C:\...\connection\http_urllib3.py", line 250, in perform_request raise ConnectionError("N/A", str(e), e) elasticsearch.exceptions.ConnectionError: Connectio
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' : {}
}
})
为什么会发生这种情况?您在示例中没有提到端口。请验证您提到的教程和以下代码段:
es = Elasticsearch(
['localhost', 'otherhost'],
http_auth=('user', 'secret'),
scheme="https",
port=443,
)
不幸的是,我也遇到了这样的问题 默认情况下,上下文中check_hostname的值为True,因此必须指定服务器_主机名。这是一个简单的解决方案,只需在创建上下文后添加以下行
context.check_hostname = False
通过执行
context.check\u hostname=False,它应该可以正常工作,这样会使连接不安全
请改用此构造函数:
Elasticsearch(
hosts=['ip_address'],,
http_auth=('elastic', 'pass'),
use_ssl=True,
verify_certs=True,
port=9200, #make sure of the port elasticsearch is using
ca_certs='/Users/raphaeldelio/ca.crt'
)
看起来与此相关: