From 4e2568574271e5e37de5e5c86e4bb12a5e661c6b Mon Sep 17 00:00:00 2001 From: aschollmeier-gcmlp Date: Wed, 4 Dec 2024 16:34:22 -0600 Subject: [PATCH 1/3] Update proxy argument in httpx Client/AsyncClient Ref: https://github.com/encode/httpx/blob/master/CHANGELOG.md#0260-20th-december-2023 --- src/zeep/transports.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/zeep/transports.py b/src/zeep/transports.py index 2a1ee8bd..0cbb05f2 100644 --- a/src/zeep/transports.py +++ b/src/zeep/transports.py @@ -183,15 +183,17 @@ def __init__( self._close_session = False self.cache = cache + proxy_kwarg_name = "proxy" if httpx.__version__ >= "0.26.0" else "proxies" + proxy_kwargs = {proxy_kwarg_name: proxy} self.wsdl_client = wsdl_client or httpx.Client( verify=verify_ssl, - proxies=proxy, timeout=timeout, + **proxy_kwargs, ) self.client = client or httpx.AsyncClient( verify=verify_ssl, - proxies=proxy, timeout=operation_timeout, + **proxy_kwargs, ) self.logger = logging.getLogger(__name__) From 411ea4ef7ec4d160dd2cb2d29288c9d34466f286 Mon Sep 17 00:00:00 2001 From: aschollmeier-gcmlp Date: Sat, 14 Dec 2024 09:34:53 -0600 Subject: [PATCH 2/3] Correct httpx version comparison --- pyproject.toml | 5 ++++- src/zeep/transports.py | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c151100a..414e83c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,10 @@ test = [ "flake8-debugger==4.1.2", "flake8-imports==0.1.1", ] -async = ["httpx>=0.15.0"] +async = [ + "httpx>=0.15.0", + "packaging", +] xmlsec = ["xmlsec>=0.6.1"] [build-system] diff --git a/src/zeep/transports.py b/src/zeep/transports.py index 0cbb05f2..f1b00565 100644 --- a/src/zeep/transports.py +++ b/src/zeep/transports.py @@ -16,6 +16,15 @@ except ImportError: httpx = None +try: + from packaging.version import Version + if Version(httpx.__version__) >= Version("0.26.0"): + HTTPX_PROXY_KWARG_NAME = "proxy" + else: + HTTPX_PROXY_KWARG_NAME = "proxies" +except ImportError: + Version = None + HTTPX_PROXY_KWARG_NAME = None __all__ = ["AsyncTransport", "Transport"] @@ -178,13 +187,15 @@ def __init__( verify_ssl=True, proxy=None, ): - if httpx is None: - raise RuntimeError("The AsyncTransport is based on the httpx module") + if httpx is None or HTTPX_PROXY_KWARG_NAME is None: + raise RuntimeError( + "To use AsyncTransport, install zeep with the async extras, " + "e.g., `pip install zeep[async]`" + ) self._close_session = False self.cache = cache - proxy_kwarg_name = "proxy" if httpx.__version__ >= "0.26.0" else "proxies" - proxy_kwargs = {proxy_kwarg_name: proxy} + proxy_kwargs = {HTTPX_PROXY_KWARG_NAME: proxy} self.wsdl_client = wsdl_client or httpx.Client( verify=verify_ssl, timeout=timeout, From c20b7ba21d815377cb5d5095eb9e9f5918fb678d Mon Sep 17 00:00:00 2001 From: aschollmeier-gcmlp Date: Sat, 14 Dec 2024 10:00:17 -0600 Subject: [PATCH 3/3] Avoid potential AttributeError in httpx version check --- src/zeep/transports.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zeep/transports.py b/src/zeep/transports.py index f1b00565..d2136373 100644 --- a/src/zeep/transports.py +++ b/src/zeep/transports.py @@ -18,10 +18,10 @@ try: from packaging.version import Version - if Version(httpx.__version__) >= Version("0.26.0"): - HTTPX_PROXY_KWARG_NAME = "proxy" - else: + if httpx is None or Version(httpx.__version__) < Version("0.26.0"): HTTPX_PROXY_KWARG_NAME = "proxies" + else: + HTTPX_PROXY_KWARG_NAME = "proxy" except ImportError: Version = None HTTPX_PROXY_KWARG_NAME = None