I'm running opensearch v 1.0.0 on docker container with the following command on the localhost
. Please consider this question IS NOT same as this post, Opensearch Docker Image Failed to establish a new connection: [Errno 111] Connection refused) since the cause of the failure is different.
docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.0.0
I'm trying to run the code in the example in the opensearch documentation , WITHOUT using ca_certs and ssl.
from opensearchpy import OpenSearch
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
# ca_certs_path = '/full/path/to/root-ca.pem' # Provide a CA bundle if you use intermediate CAs with your root CA.
# Optional client certificates if you don't want to use HTTP basic authentication.
# client_cert_path = '/full/path/to/client.pem'
# client_key_path = '/full/path/to/client-key.pem'
# Create the client with SSL/TLS enabled, but hostname verification disabled.
client = OpenSearch(
hosts = [{'host': host, 'port': port}],
http_compress = True, # enables gzip compression for request bodies
http_auth = auth,
# client_cert = client_cert_path,
# client_key = client_key_path,
use_ssl = False,
verify_certs = False,
ssl_assert_hostname = False,
ssl_show_warn = False,
# ca_certs = ca_certs_path
)
# Create an index with non-default settings.
index_name = 'python-test-index'
index_body = {
'settings': {
'index': {
'number_of_shards': 4
}
}
}
response = client.indices.create(index_name, body=index_body)
print('\nCreating index:')
print(response)
And it gives me the following error.
ConnectionError: ConnectionError(('Connection aborted.', RemoteDisconnected('Remote end
closed connection without response'))) caused by: ProtocolError(('Connection aborted.',
RemoteDisconnected('Remote end closed connection without response')))
After that I ran the following command on the terminal , It gives the expected output, which says that OpenSearch runs finely in docker.
$ curl -XGET https://localhost:9200 -u 'admin:admin' --insecure
How to fix this.
CodePudding user response:
You are setting use_ssl=False
, but the opensearch
Docker image appears to create an SSL server by default. You can see this if you watch the containers logs when you attempt to make a non-SSL connection:
io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record
If I modify your code to have use_ssl=True
, then it runs successfully:
$ python opensearch_test.py
Loading .env environment variables...
Creating index:
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'python-test-index'}