Repository navigation
InvalidURL error when NO_PROXY environment variable contains newline characters #3303
Description
Activity
Hi, I'd like to work on this. I'll submit a PR shortly.
- added a commit that references this issue
on Jun 11, 2026 If this is still open and there is no active PR in progress, I would like to take a look. The environment sanitization path seems small enough to verify with a focused repro and test.
Implemented in the existing PR for this branch. The client now temporarily normalizes NO_PROXY /
o_proxy values before constructing the default httpx client, so newline-delimited entries no longer crash client initialization on Windows or Unix. I added regression tests for both sync and async constructors.Thanks. I will step back from this since there is already an active fix in progress.
Stepping back here since there is already an active fix in progress for this issue. I don't want to duplicate effort.
Hi, I'd like to work on this. I'll submit a PR shortly.
- added a commit that references this issue
on Jul 20, 2026 - added 7 commits that reference this issue
on Aug 7, 2026 Working on this in PR #3631.
- added a commit that references this issue
on Aug 22, 2026 - added a commit that references this issue
on Sep 2, 2026 marcuswood-oai commented
on Sep 9, 2026 ContributorMore actionsThank you for the report. We understand how multiline Docker Compose configuration can lead to this. HTTPX2 expects a comma-separated NO_PROXY list, so please use
NO_PROXY=localhost,192.168.1.1rather than separating the hosts with newlines.We’re closing this because we’re keeping the SDK consistent with HTTPX2’s proxy parsing. Broader separator support belongs in the transport library; we won’t add SDK-specific normalization.
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When the NO_PROXY environment variable contains newline characters (common in Docker environments, .env files, or shell scripts), creating an OpenAI client raises InvalidURL.
The error occurs because httpx's get_environment_proxies() only splits NO_PROXY by comma ,, not by newline \n. When a newline is present in the value, it becomes part of the hostname and triggers
URL validation failure.
The fix in httpx would be trivial, but the encode/httpx project is currently not actively accepting external PRs or issues.
Suggesting that openai-python sanitize proxy-related environment variables when initializing the internal httpx client.
To Reproduce
import os
os.environ['NO_PROXY'] = 'localhost\n192.168.1.1'
from openai import OpenAI
client = OpenAI(api_key='sk-test')
Error:
httpx.InvalidURL: Invalid non-printable ASCII character in URL, '\n' at position 16
Code snippets
OS
Windows / Linux (any)
Python version
3.11+
Library version
openai: latest