Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client fails to connect to self-managed Elasticsearch instance at https://localhost:9200 using all methods described in documentation #2520

Closed
jackgray opened this issue Apr 3, 2024 · 2 comments

Comments

@jackgray
Copy link

jackgray commented Apr 3, 2024

Elasticsearch version (bin/elasticsearch --version):
8.7.1
elasticsearch-py version (elasticsearch.__versionstr__):
8.7.0
Please make sure the major version matches the Elasticsearch server you are running.
There is no python client version 8.7.1
Description of the problem including expected versus actual behavior:

Following documentation does not lead to successful python client connection.

https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/connecting.html
https://github.com/elastic/elasticsearch/blob/8.13/docs/reference/setup/install/docker/docker-compose.yml

The cluster (single-node mode) otherwise behaves as expected.
curl -k -u username:password https://localhost:9200 succeeds:

{
  "name" : "es01",
  "cluster_name" : "elastic-cluster",
  "cluster_uuid" : "redacted",
  "version" : {
    "number" : "8.7.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "redacted",
    "build_date" : "2023-04-27T04:33:42.127815583Z",
    "build_snapshot" : false,
    "lucene_version" : "9.5.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

creating a fingerprint with openssl s_client -connect localhost:9200 -servername localhost -showcerts </dev/null 2>/dev/null | openssl x509 -fingerprint -sha256 -noout -in /dev/stdin succeeds

Initiation via python client does not:

client = Elasticsearch(
              "https://localhost:9200",
              # api_key="redacted==",     # base64
              # ca_certs="/opt/src/ca.crt",
             ssl_assert_fingerprint="redacted",
              basic_auth=('username', 'password')
            )
client.info()

Error:

elastic_transport.ConnectionError: Connection error caused by: ConnectionError(Connection error caused by: NewConnectionError(<elastic_transport._node._urllib3_chain_certs.HTTPSConnection object at 0x7fb6b2d2ba10>: Failed to establish a new connection: [Errno 111] Connection refused))

Steps to reproduce:

see above steps. Follow this guide to set up elastic stack: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html, then this guide to connect with python client: https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/connecting.html

Connection error occurs using API key, basic auth, verify_certs=True, verify_certs=False, mounting CA cert, and using CA fingerprint

@pquentin
Copy link
Member

Hello, and sorry for the delay getting back to you.

This does not appear to be an HTTPS issue at all, "connection refused" means that the client cannot perform a TCP connection. Do you get a different error when using requests directly?

import requests
requests.get("https://localhost:9200")

Also please make sure to double check the host and port are correct.

@pquentin
Copy link
Member

Closing as I've not heard back from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants