Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “弹性”为什么提出这个例外;elasticsearch.exceptions.ConnectionError:ConnectionError(检查“主机名需要服务器”主机名)“;?_Python_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Ssl - Fatal编程技术网 elasticsearch,ssl,Python,elasticsearch,Ssl" /> elasticsearch,ssl,Python,elasticsearch,Ssl" />

Python “弹性”为什么提出这个例外;elasticsearch.exceptions.ConnectionError:ConnectionError(检查“主机名需要服务器”主机名)“;?

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

我试图从python脚本查询elasticsearch,但引发了一个异常

我遵循官方指南,如。 但当我试图查询elasticsearch时,没有成功。例外情况如下:

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'
)

看起来与此相关: