Skip to content

Update proxy argument in httpx Client/AsyncClient #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 17 additions & 4 deletions src/zeep/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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__)

Expand Down