Skip to content

Commit 411ea4e

Browse files
Correct httpx version comparison
1 parent 4e25685 commit 411ea4e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ test = [
5353
"flake8-debugger==4.1.2",
5454
"flake8-imports==0.1.1",
5555
]
56-
async = ["httpx>=0.15.0"]
56+
async = [
57+
"httpx>=0.15.0",
58+
"packaging",
59+
]
5760
xmlsec = ["xmlsec>=0.6.1"]
5861

5962
[build-system]

src/zeep/transports.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
except ImportError:
1717
httpx = None
1818

19+
try:
20+
from packaging.version import Version
21+
if Version(httpx.__version__) >= Version("0.26.0"):
22+
HTTPX_PROXY_KWARG_NAME = "proxy"
23+
else:
24+
HTTPX_PROXY_KWARG_NAME = "proxies"
25+
except ImportError:
26+
Version = None
27+
HTTPX_PROXY_KWARG_NAME = None
1928

2029
__all__ = ["AsyncTransport", "Transport"]
2130

@@ -178,13 +187,15 @@ def __init__(
178187
verify_ssl=True,
179188
proxy=None,
180189
):
181-
if httpx is None:
182-
raise RuntimeError("The AsyncTransport is based on the httpx module")
190+
if httpx is None or HTTPX_PROXY_KWARG_NAME is None:
191+
raise RuntimeError(
192+
"To use AsyncTransport, install zeep with the async extras, "
193+
"e.g., `pip install zeep[async]`"
194+
)
183195

184196
self._close_session = False
185197
self.cache = cache
186-
proxy_kwarg_name = "proxy" if httpx.__version__ >= "0.26.0" else "proxies"
187-
proxy_kwargs = {proxy_kwarg_name: proxy}
198+
proxy_kwargs = {HTTPX_PROXY_KWARG_NAME: proxy}
188199
self.wsdl_client = wsdl_client or httpx.Client(
189200
verify=verify_ssl,
190201
timeout=timeout,

0 commit comments

Comments
 (0)