You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Python远程连接Elastic节点遇证书验证问题求助

Python连接Elasticsearch节点证书验证失败问题

我在Ubuntu服务器部署了Elasticsearch,从Windows 10机器用Python连接单个节点时,持续遇到证书相关错误。

  • 浏览器连接正常:从Windows机器通过浏览器访问https://10.20.20.131:9200,能正常通过验证并得到预期输出(显示Elasticsearch节点信息的JSON界面)。
  • Python连接失败:试过官方教程的所有示例都无效,以下是我最新尝试的代码:
from elasticsearch import Elasticsearch
from ssl import create_default_context

es_username = 'elastic'
es_password = 'xuVmOMJqLGbLskP3PTpT'
es_host = '10.20.20.131'
es_port = 9200
cafile = r'C:\Users\user\Desktop\PYTHON\certificate.crt'


context = create_default_context(cafile=cafile)
es = Elasticsearch(
    ['https://10.20.20.131'],
    basic_auth=(es_username, es_password),
    scheme="https",
    verify_certs=False,
    port=9200,
    ssl_context=context,
)

print(es.info())

我已经将Ubuntu服务器上的证书复制到Windows机器的指定路径,但运行代码仍提示SSL: CERTIFICATE_VERIFY_FAILED的证书验证错误。

不知道哪里操作有误,希望能得到解决帮助。


内容的提问来源于stack exchange,提问作者PythonNoob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 23:01:37