fix: sanitize NO_PROXY newlines before httpx client init#3395
Open
TasadduqB wants to merge 1 commit into
Open
Conversation
When NO_PROXY contains newline characters (common in Docker .env files and shell scripts), httpx's URL parser rejects the non-printable characters with InvalidURL. Since httpx is not accepting external fixes, sanitize NO_PROXY/no_proxy by replacing newlines with commas before httpx reads the environment. Closes openai#3303
38215cb to
8125b58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
httpx.InvalidURLwhenNO_PROXYorno_proxyenvironment variables contain newline characters (common in Docker.envfiles, shell scripts, and CI environments)_sanitize_proxy_env()helper in_base_client.pythat replaces newlines with commas inNO_PROXY/no_proxybefore httpx reads the environment_DefaultHttpxClient,_DefaultAsyncHttpxClient,_DefaultAioHttpClient)Context
httpx's
get_environment_proxies()only splitsNO_PROXYby comma, not by newline. When a newline is present, it becomes part of the hostname and triggers URL validation failure. Since httpx is not currently accepting external PRs, this fix sanitizes at the openai-python layer.Closes #3303
Test plan
TestOpenAI): newline inNO_PROXY, newline inno_proxy, no-newline passthroughTestAsyncOpenAI): same coveragetest_proxy_environment_variablestests still pass (both sync and async)