opensearch-project / opensearch-py

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

Unhelpful error message, AttributeError: 'bool' object has no attribute 'strip' #691

Closed matthewdeanmartin closed 6 months ago

matthewdeanmartin commented 6 months ago

The bulk insert (opensearchpy.helpers.parallel_bulk) functionality fails on a cryptic error message from urllib3

[WARNING] opensearch: POST https://[snip].us-east-1.es.amazonaws.com:443/_bulk [status:N/A request:0.074s]
Traceback (most recent call last):
File "/var/lang/lib/python3.12/site-packages/opensearchpy/connection/http_urllib3.py", line 264, in perform_request
response = self.pool.urlopen(
^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen
httplib_response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request
self._validate_conn(conn)
File "/var/lang/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn
conn.connect()
File "/var/lang/lib/python3.12/site-packages/urllib3/connection.py", line 472, in connect
_match_hostname(cert, self.assert_hostname or server_hostname)
File "/var/lang/lib/python3.12/site-packages/urllib3/connection.py", line 540, in _match_hostname
stripped_hostname = asserted_hostname.strip("u[]")
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'strip'

This is running on python 3.12, AWS Linux 2023, urllib3==1.26.18, opensearch-py==2.4.2 when attempting to load large quantities of data. I'm going to try to see if the requests library has the same problem.

The internet has no useful suggestions on what is wrong.

saimedhi commented 6 months ago

Hello @matthewdeanmartin, I feel this is related to PR.

saimedhi commented 6 months ago

If I've missed anything, please share the code used to create the client. Thank you.

matthewdeanmartin commented 6 months ago

I wish I was setting ssl_assert_hostname because I could fix that. opensearchpy code is setting that value.

Specifying the connection_class is the last interaction I have with Urllib3HttpConnection.

    def client(self) -> opensearchpy.OpenSearch:
        kwargs = {
            "verify_certs": True,
            # connection_class=opensearchpy.RequestsHttpConnection,
            # only use for request4auth
            "connection_class": opensearchpy.Urllib3HttpConnection,
            "timeout": self.elastic_search_timeout,
            "retry_on_timeout": True,
            "ssl_show_warn": True,
        }
        return opensearchpy.OpenSearch([self.elastic_search_url_parts], **kwargs)
matthewdeanmartin commented 6 months ago

Nevermind, found the issue. The params of OpenSearch are passed to the connection_class and I had some copy-paste from doucmentation that set the ssl_assert_hostname instead of verify_certs.

I guess this is the cost of using an untyped language.