opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
359 stars 178 forks source link

[BUG] ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x163566bf0>: Failed to establish a new connection: [Errno 8] #567

Closed sunx0766 closed 1 year ago

sunx0766 commented 1 year ago

What is the bug?

I have an Amazon OpenSearch instance. When I try to connect to it with opensearchpy on a jupyter notebook .ipynb I get this error:

ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x163566bf0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x163566bf0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known)

How can one reproduce the bug?

_I ran this code in a jyputer notebook. I have an amazon OpenSearch instance that is up and running on the VPC. For the aws_opensearchurl, I got it from AWS --> Amazon OpenSearch Service --> Domains --> Domain endpoint (VPC) and copied the URL from there.

from opensearchpy import OpenSearch
host = 'aws_opensearch_url'
#port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
client = OpenSearch(
    hosts = [{'host': host}],
    http_auth = auth,
    use_ssl = False,
    verify_certs = False
)
info = client.info()
print(f"Welcome to {info['version']['distribution']} {info['version']['number']}!")

What is the expected behavior?

a print statement of the version info

What is your host/environment?

LangChain: 0.0.330 opensearachpy: (2, 3, 2) OS Type: Darwin Python Version: 3.10.13

Do you have any additional context?

To double check that the instance is up and running, I ran curl awe_opensearch_url -u 'username:password' and I was able to get the cluster information

_I tried changing the parameters of use_ssl = True, verify_certs=True, with or without port, all didn't work_

_I also tried with all 3 connection classes as described in the connection_classes.md, still had no luck_

dblock commented 1 year ago

Let's start with a basic sample without the langchain stack? Want to try to run https://github.com/dblock/opensearch-python-client-demo?

I wold also enable more logging:

import logging

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
dblock commented 1 year ago

I am 100% sure this is not a client problem and something to do with the host name/network, so I am going to close this.

@sunx0766 Let us know if curl works successfully against your server, and if so enable logging. If there's a client bug we'll reopen of course.

Mdelaf commented 5 months ago

For anyone else having issues to connect to their AWS OpenSearch domain, make sure that:

dblock commented 5 months ago

@Mdelaf it would be great to update docs/guides, maybe https://github.com/opensearch-project/opensearch-py/blob/main/guides/auth.md?