Add support for proxy environment variables in publish#2233
Add support for proxy environment variables in publish#2233bartosz121 wants to merge 1 commit intopypa:masterfrom
publish#2233Conversation
- httpx does not honor proxy environment variables automatically when a custom transport is passed, like in this case - we use `httpx._utils.get_environment_proxies`[0] to stay consistent with httpx behavior instead of reimplementing env var parsing ourselves [0] https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_utils.py#L30
| proxy_map = get_environment_proxies() | ||
| mounts: dict[str, httpx.HTTPTransport | None] = {} | ||
| for pattern, proxy in proxy_map.items(): | ||
| if proxy is None: | ||
| mounts[pattern] = None | ||
| else: | ||
| mounts[pattern] = httpx.HTTPTransport( | ||
| retries=3, verify=self.__verify, cert=self.__cert, trust_env=True, proxy=proxy | ||
| ) |
There was a problem hiding this comment.
doesn't trust_env=True do the same thing? you can avoid depending on _utils
disclaimer: not a maintainer
There was a problem hiding this comment.
Yes, but only if no custom transport is provided [0]. httpx.Client only applies env proxies automatically when trust_env=True and transport is None.
I considered removing the custom transport entirely and relying on trust_env=True, but that would drop retries=3 because httpx.Client does not expose retries in its constructor
There was a problem hiding this comment.
Yeah, using the private _utils import from httpx is not ideal. The cleanest alternative would be to drop the custom transport and use a plain httpx.Client, but that would also mean dropping retries=3. I’m happy to go either way if maintainers would prefer the simpler approach
stumbled across this at work, fixes #1908
httpx._utils.get_environment_proxies[0] to stay consistent with httpx behavior instead of reimplementing env var parsing ourselves[0] https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_utils.py#L30