opensearch-project / opensearch-py

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

[BUG] Cannot connect to a Docker local development cluster using opensearch-py #193

Closed dylanjcastillo closed 2 years ago

dylanjcastillo commented 2 years ago

What is the bug?

I cannot connect to a local development cluster using opensearch-py. If I use curl it works correctly.

How can one reproduce the bug?

  1. Run Docker's image for local development: docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:2.2.0
  2. Run the following code in python:

host = 'localhost' port = 9200 auth = ('admin', 'admin')

client = OpenSearch( hosts = [{'host': host, 'port': port}], http_auth = auth, use_ssl = False, verify_certs = False, ssl_assert_hostname = False, ssl_show_warn = False, ) client.info()


### What is the expected behavior?
I should get info about the cluster.

### What is your host/environment?
  Model Name: MacBook Air
  Chip: Apple M1
  Total Number of Cores: 8 (4 performance and 4 efficiency)
  Memory: 16 GB
  System Version: macOS 12.5.1 (21G83)
  Kernel Version: Darwin 21.6.0

### Do you have any screenshots?
It works well when I use `curl`: https://imgur.com/a/0O15MaM

### Do you have any additional context?
Here's the error I get in the Jupyter Notebook:

ConnectionError: ConnectionError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))) caused by: ProtocolError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))


Here's the error I get in the terminal running the cluster:

[2022-08-30T13:56:34,254][ERROR][o.o.s.s.h.n.SecuritySSLNettyHttpServerTransport] [db120fd1fe80] Exception during establishing a SSL connection: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record:

dtaivpp commented 2 years ago

Hey @dylanjcastillo you need to set use_ssl to true and then the rest should be correct. By default the container forces SSL even though it’s using self signed certs.

dtaivpp commented 2 years ago

Let me know if you still have issues after you try that.

dylanjcastillo commented 2 years ago

That was it! Thank you, it's working now.

dtaivpp commented 2 years ago

Awesome! It’s a pretty common issue with the client. I actually wonder if we could raise a specific exception to alert people to try and change the verify setting

wbeckler commented 2 years ago

Would either of you be up for creating an issue to change this default, and/or to drafting a PR?

dylanjcastillo commented 2 years ago

Hey @wbeckler, yes, I'd be happy to! Seems like a good first issue to contribute

invalidred commented 3 months ago

Faced same issue today when I tried to connect to local k3d open search cluster installed via helm. Setting use_ssl = True indeed solved this issue.