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 2a1ee8bd..d2136373 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 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 __all__ = ["AsyncTransport", "Transport"] @@ -178,20 +187,24 @@ 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_kwargs = {HTTPX_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__)