Skip to content

fix: sanitize NO_PROXY newlines before httpx client init#3395

Open
TasadduqB wants to merge 1 commit into
openai:mainfrom
TasadduqB:fix/sanitize-no-proxy-newlines
Open

fix: sanitize NO_PROXY newlines before httpx client init#3395
TasadduqB wants to merge 1 commit into
openai:mainfrom
TasadduqB:fix/sanitize-no-proxy-newlines

Conversation

@TasadduqB

@TasadduqB TasadduqB commented Jun 11, 2026

Copy link
Copy Markdown

Summary

  • Fixes httpx.InvalidURL when NO_PROXY or no_proxy environment variables contain newline characters (common in Docker .env files, shell scripts, and CI environments)
  • Adds a _sanitize_proxy_env() helper in _base_client.py that replaces newlines with commas in NO_PROXY/no_proxy before httpx reads the environment
  • Wired into all three default client constructors (_DefaultHttpxClient, _DefaultAsyncHttpxClient, _DefaultAioHttpClient)

Context

httpx's get_environment_proxies() only splits NO_PROXY by 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

  • Added 3 sync tests (TestOpenAI): newline in NO_PROXY, newline in no_proxy, no-newline passthrough
  • Added 3 async tests (TestAsyncOpenAI): same coverage
  • Verified existing test_proxy_environment_variables tests still pass (both sync and async)
  • All 8 proxy-related tests pass

@TasadduqB TasadduqB requested a review from a team as a code owner June 11, 2026 10:22
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
@TasadduqB TasadduqB force-pushed the fix/sanitize-no-proxy-newlines branch from 38215cb to 8125b58 Compare June 11, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidURL error when NO_PROXY environment variable contains newline characters

1 participant