简体   繁体   English

Elasticsearch 无法连接 python 客户端,ssl 错误

[英]Elasticsearch cannot connect with python client, ssl error

I am hosting standalone elasticsearch on external server.我在外部服务器上托管独立的弹性搜索。 Using certificate and login-password authentication.使用证书和登录密码验证。 I am able to connect to it using browser or postman.我可以使用浏览器或邮递员连接到它。

However when I try to do it, using python client it doesn't work.但是,当我尝试这样做时,使用 python 客户端它不起作用。 My connection code:我的连接代码:

        self.es = Elasticsearch(
            address,
            ca_certs=cert_path,
            basic_auth=(user, password),
        )

Error message:错误信息:

elastic_transport.TlsError: TLS error caused by: TlsError(TLS error caused by: SSLError(hostname '34.116.***.***' doesn't match either of 'localhost', '172.19.0.2', '127.0.0.1', 'bde723133f75'))

Please try creating an ssl_context object and set the verification mode on the context.请尝试创建一个 ssl_context 对象并在上下文中设置验证模式。

import ssl
from elasticsearch.connection import create_ssl_context

ssl_context = create_ssl_context(<use `cafile`, or `cadata` or `capath` to set your CA or CAs)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
es = Elasticsearch('localhost', ssl_context=context, timeout=60)

or you can try with this:或者你可以试试这个:

from ssl import create_default_context
from elasticsearch import Elasticsearch
es = Elasticsearch(["https://username:password@yourserver:9200"], verify_certs=False)
es.cat.nodes()

Option 2 will be warning, because it disable SSL with link url using HTTPS, but it work.选项 2 将发出警告,因为它使用 HTTPS 禁用带有链接 url 的 SSL,但它可以工作。

Using some help from Luc answer: Just before i tried something like this:使用 Luc 的一些帮助回答:就在我尝试这样的事情之前:

from ssl import create_default_context
import ssl
        context = create_default_context(capath=cert_path)
        context.check_hostname = False
        context.verify_mode = ssl.CERT_NONE
        self.es = Elasticsearch(
            address,
            ssl_context=context,
            basic_auth=(user, password),
            verify_certs=False,
        )

I am getting some warnings but other then that it works我收到一些警告,但除此之外它有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 SSL 连接到 Elasticsearch 和 python? - How to connect to Elasticsearch with python using SSL? Java SSL套接字无法从客户端连接 - Java SSL socket cannot connect from client Python MySQLdb 无法连接服务器,SSL 问题 - Python MySQLdb cannot connect to server, SSL Issue Python 请求 - 客户端证书的 SSL 错误 - Python Requests - SSL error for client side cert 如何将 Python Elasticsearch 客户端连接到 Bitnami ELK VM? - How to connect Python Elasticsearch client to Bitnami ELK VM? pymysql无法与SSL连接 - pymysql cannot connect with SSL SSL 错误(错误握手),证书有效 | Elasticsearch &amp; Python - SSL Error (bad handshake) with valid certificate | Elasticsearch & Python Elasticsearch:安装防护罩后无法使用python连接 - Elasticsearch : Cannot connect using python when shield is installed 在 Mac 上使用 Python 连接到 Oracle 时出错 - 找不到 Oracle 客户端库 - Getting Error Connect to Oracle using Python On Mac - Cannot locate Oracle Client library 将tlslite python服务器与SRP一起用于打开的ssl客户端时失败,并显示“ SSL_connect:SSLv3读取服务器密钥交换B中的错误” - Using tlslite python server with SRP against an open ssl client fails with “SSL_connect:error in SSLv3 read server key exchange B”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM