我在docker容器上运行openSearchv1.0.0,在localhost上使用以下命令。请考虑这个问题,不是和这篇文章一样,未能建立新连接:[Errno 111]连接被拒绝)是因为失败的原因不同。
docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.0.0我试图在opensearch 文档,中运行示例中的代码,而不使用ca_certs和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)它给了我以下的错误。
ConnectionError: ConnectionError(('Connection aborted.', RemoteDisconnected('Remote end
closed connection without response'))) caused by: ProtocolError(('Connection aborted.',
RemoteDisconnected('Remote end closed connection without response')))在此之后,我在终端上运行了以下命令,它给出了预期的输出,即OpenSearch在docker中运行得很好。
$ curl -XGET https://localhost:9200 -u 'admin:admin' --insecure如何解决这个问题。
发布于 2022-06-19 21:40:41
您正在设置use_ssl=False,但默认情况下,opensearch Docker映像似乎会创建opensearch服务器。当您尝试建立非SSL连接时,如果您查看容器日志,您可以看到这一点:
io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record如果我修改您的代码使其具有use_ssl=True,那么它将成功运行:
$ python opensearch_test.py
Loading .env environment variables...
Creating index:
{'acknowledged': True, 'shards_acknowledged': True, 'index': 'python-test-index'}https://stackoverflow.com/questions/72680315
复制相似问题