Unable to connect to opensearch by python client to the ingress with subpath

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
2.14.0

Describe the issue:
i configure connection to backend Opensearch on ingress with SubPath like that.
https://opens.com/opensearch and i want to connect from python client .

like that:
client = OpenSearch(
hosts = [{‘host’: 'https://opens.com/opensearch/, ‘port’: ‘443’}],
http_auth = auth,
http_compress = True,
use_ssl = True,
verify_certs = True,
ssl_assert_hostname = ‘opens.com’,
ssl_show_warn = True,
)

and i got failed to connetion
An error occurred while removing the OpenSearch index: ConnectionError(<urllib3.connection.HTTPSConnection object at 0x7f52b4904b80>: Failed to resolve ‘https://opens.com/opensearch/’ ([Errno -2] Name or service not known)) caused by: NameResolutionError(<urllib3.connection.HTTPSConnection object at 0x7f52b4904b80>: Failed to resolve ‘https://opens.com/opensearch/’ ([Errno -2] Name or service not known))

if i try to connect with the curl i got answer.

curl https://opens.com/opensearch/ -u admin:admin
{
“name” : “opensearch-cluster-data-1”,
“cluster_name” : “opensearch-cluster”,
“cluster_uuid” : “jpbABLUDRJmViZraPP6K3A”,
“version” : {
“distribution” : “opensearch”,
“number” : “2.14.0”,
“build_type” : “tar”,
“build_hash” : “aaa555453f4713d652b52436874e11ba258d8f03”,
“build_date” : “2024-05-09T18:51:00.973564994Z”,
“build_snapshot” : false,
“lucene_version” : “9.10.0”,
“minimum_wire_compatibility_version” : “7.10.0”,
“minimum_index_compatibility_version” : “7.0.0”
},
“tagline” : “The OpenSearch Project: https://opensearch.org/
}

the url https://opens.com/opensearch/ is an example, of course.

ok, i find the solution,
u need to add subPath as a Url prefix parmeters in the hosts array,
example:
client = OpenSearch(
hosts = [{‘host’: ‘opens.com’, ‘port’: ‘443’, ‘url_prefix’: ‘opensearch’ }],
http_auth = auth,
http_compress = True,
use_ssl = True,
verify_certs = True,
ssl_assert_hostname = ‘master01.ent.core.medtronic.com’,
ssl_show_warn = True,
)

1 Like