The Fix
Fixes the handling of IPv6 addresses in URLs by ensuring that they are properly enclosed in square brackets.
Based on closed encode/httpx issue #1311 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -108,6 +108,11 @@ def __init__(
scheme = raw_scheme.decode("ascii")
host = raw_host.decode("ascii")
+ if host and ":" in host and host[0] != "[":
+ # it's an IPv6 address, so it should be enclosed in "[" and "]"
+ # ref: https://tools.ietf.org/html/rfc2732#section-2
import httpx
import requests
url = 'http://172.17.0.2:5678'
url6 = 'http://[2001:db8:1::242:ac11:2]:5678'
print(requests.get(url))
print(requests.get(url6))
print(httpx.get(url))
print(httpx.get(url6))
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nFixes the handling of IPv6 addresses in URLs by ensuring that they are properly enclosed in square brackets.\nWhen NOT to use: Do not apply this fix if the application does not use IPv6 addresses.\n\n
Why This Fix Works in Production
- Trigger: <Response [200]>
- Mechanism: The URL handling for IPv6 addresses did not properly strip square brackets
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- The URL handling for IPv6 addresses did not properly strip square brackets
- Surfaces as: <Response [200]>
Proof / Evidence
- GitHub issue: #1311
- Fix PR: https://github.com/encode/httpx/pull/1349
- Reproduced locally: No (not executed)
- Last verified: 2026-02-12
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.39
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“To my eye it looks like the problem is with the brackets in the URL - they are never stripped URL.host returns [2001:db8:1::242:ac11:2] which is…”
“Interesting, yup”
“I have the same issue and received the following message: shaman-install configuration.yaml 2021-04-13 08:31:59.315 | DEBUG | bb_wrapper.tunable_component.install_component:install_component:36 - Sending component data {'components': {'shaman_pbo_msr_profiling”
Failure Signature (Search String)
- <Response [200]>
Error Message
Stack trace
Error Message
-------------
<Response [200]>
<Response [200]>
<Response [200 OK]>
Traceback (most recent call last):
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_exceptions.py", line 339, in map_exceptions
yield
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpx/_client.py", line 858, in _send_single_request
ext={"timeout": timeout.as_dict()},
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection_pool.py", line 195, in request
method, url, headers=headers, stream=stream, ext=ext
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 87, in request
self.socket = self._open_socket(timeout)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_sync/connection.py", line 113, in _open_socket
local_address=self.local_address,
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_backends/sync.py", line 144, in open_tcp_stream
return SyncSocketStream(sock=sock)
File "/home/user/.local/share/pyenv/versions/3.7.6/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/user/repos/lb-test/.venv/lib/python3.7/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc) from None
httpcore.ConnectError: [Errno -2] Name or service not
... (truncated) ...
Minimal Reproduction
import httpx
import requests
url = 'http://172.17.0.2:5678'
url6 = 'http://[2001:db8:1::242:ac11:2]:5678'
print(requests.get(url))
print(requests.get(url6))
print(httpx.get(url))
print(httpx.get(url6))
Environment
- Python: 3.7
What Broke
HTTP requests to IPv6 addresses failed with a ConnectError.
Why It Broke
The URL handling for IPv6 addresses did not properly strip square brackets
Fix Options (Details)
Option A — Apply the official fix
Fixes the handling of IPv6 addresses in URLs by ensuring that they are properly enclosed in square brackets.
Fix reference: https://github.com/encode/httpx/pull/1349
Last verified: 2026-02-12. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the application does not use IPv6 addresses.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.