From 73f9c170719ab8401b80405f28b14d6a92b3c5c6 Mon Sep 17 00:00:00 2001 From: Carl Smedstad Date: Wed, 12 Mar 2025 16:55:14 +0100 Subject: [PATCH] Ensure compatibility with httpx v0.28.0+ (#222) Co-authored-by: Quentin Pradet (cherry picked from commit 8b66f4080bda3f47d214198a2f70cc16e618c100) --- elastic_transport/_node/_http_httpx.py | 8 ++++++++ setup.py | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/elastic_transport/_node/_http_httpx.py b/elastic_transport/_node/_http_httpx.py index ecbb0b0..04ceb60 100644 --- a/elastic_transport/_node/_http_httpx.py +++ b/elastic_transport/_node/_http_httpx.py @@ -158,6 +158,14 @@ async def perform_request( # type: ignore[override] ) elif isinstance(e, ssl.SSLError): err = TlsError(str(e), errors=(e,)) + # Detect SSL errors for httpx v0.28.0+ + # Needed until https://github.com/encode/httpx/issues/3350 is fixed + elif isinstance(e, httpx.ConnectError) and e.__cause__: + context = e.__cause__.__context__ + if isinstance(context, ssl.SSLError): + err = TlsError(str(context), errors=(e,)) + else: + err = ConnectionError(str(e), errors=(e,)) else: err = ConnectionError(str(e), errors=(e,)) self._log_request( diff --git a/setup.py b/setup.py index da2e556..b317cd4 100644 --- a/setup.py +++ b/setup.py @@ -65,8 +65,6 @@ "requests", "aiohttp", "httpx", - # https://github.com/encode/httpx/discussions/3214#discussioncomment-10830925 - "httpcore<1.0.6", "respx", "opentelemetry-api", "opentelemetry-sdk",