gpt4 book ai didi

python - 有效证书的 SSL 错误(错误握手)| Elasticsearch 和 Python

转载 作者:行者123 更新时间:2023-12-02 23:49:10 26 4
gpt4 key购买 nike

我通过 Python 脚本将数据传递给 Elasticsearch (ES)。首先,我用自签名证书保护了 ES,一切都按预期工作。然后,我切换到更受信任的证书(Let's Encrypt)。请注意,我可以毫无问题地访问我的 ES 集群。 Let's Encrypt 证书被我的浏览器信任 + 被与 ES 对话的应用程序信任,没问题。但是当我尝试使用新证书将数据从我的 Python 脚本传递到 ES 时,我收到以下错误:

urllib3.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

我本以为自签名证书会出现此错误,但 Let's encrypt 不会出现此错误。我可以避免它的唯一方法是将设置更改为 verify=False ,这不是长久之计。

在收到上述错误消息之前,我收到以下错误: elasticsearch.exceptions.SSLError: ConnectionError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)) caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777))
我通过执行 找到了解决方法 pip install requests . 但是,之后我收到了我提到的第一个错误(握手错误)。 我知道这意味着证书不受信任。但是,如果它适用于自签名证书而不适用于浏览器和应用程序信任的 Let's Encrypt 证书,这怎么可能呢?例如。如果我在 https://my-IP:9200 上调用 ES ,我的浏览器没有发出警告,而自签名证书将发出警告。

一些附加信息
  • python3
  • urllib3 1.25.7
  • 证书 2019.9.11
  • Ubuntu 18.04

  • 所以,基本上一切都是最新的。我还通过降级 certifi 和/或 urllib3 尝试了建议的解决方案,但它不起作用。一个建议是将 urllib3 降级到版本 1.25 以下(但正如我所说,它在我的情况下不起作用)。

    有任何想法吗?

    最佳答案

    您需要先安装证书,然后将其用于连接ElasticsearchPython

    host = 'mydomain.com:9200'

    client = Elasticsearch(host, http_auth=('admin', 'pass'), scheme="https", use_ssl=True, ca_certs='C:/my_path/CertificateFile.cer.pem', port=443)


    try:
    info = json.dumps(client.info(), indent=4)
    print ("Elasticsearch client info():", info)

    except exceptions.ConnectionError as err:
    print ("\nElasticsearch info() ERROR:", err)
    print ("\nThe client host:", host, "is invalid or cluster is not running")
    client = None
    回复:
    > Elasticsearch client info(): {
    > "name": "my_name",
    > "cluster_name": "my_cluster_name",
    > "cluster_uuid": "fBRShbkSRy2vcfQJZsojGA",
    > "version": {
    > "number": "7.3.0",
    > "build_flavor": "default",
    > "build_type": "tar",
    > "build_hash": "de777fa",
    > "build_date": "2019-07-24T18:30:11.767338Z",
    > "build_snapshot": false,
    > "lucene_version": "8.1.0",
    > "minimum_wire_compatibility_version": "6.8.0",
    > "minimum_index_compatibility_version": "6.0.0-beta1"
    > },
    > "tagline": "You Know, for Search" }
    elasticsearch.yml:
    xpack.security.enabled: true
    xpack.ml.enabled: false
    xpack.security.transport.ssl.enabled: true
    xpack.security.transport.ssl.verification_mode: certificate
    xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
    xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
    xpack.security.http.ssl.enabled: true
    xpack.security.http.ssl.keystore.path: elastic-certificates.p12
    xpack.security.http.ssl.truststore.path: elastic-certificates.p12

    关于python - 有效证书的 SSL 错误(错误握手)| Elasticsearch 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58887142/

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