The Fix
pip install urllib3==1.25
Based on closed urllib3/urllib3 issue #707 · 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%.
@@ -68,8 +68,7 @@ def __init__(self, host, port=None):
raise LocationValueError("No host specified.")
- # httplib doesn't like it when we include brackets in ipv6 addresses
- self.host = host.strip('[]')
+ self.host = host
Option A — Upgrade to fixed release\npip install urllib3==1.25\nWhen NOT to use: This fix should not be applied if the application relies on the square brackets for other functionality.\n\n
Why This Fix Works in Production
- Trigger: Error using https and ipv6: InvalidURL("nonnumeric port: '4f7b'",)
- Mechanism: The code incorrectly stripped square brackets from IPv6 addresses, causing an InvalidURL error
- Why the fix works: The fix removes the requirement for square brackets in IPv6 addresses when using httplib, resolving the InvalidURL error. (first fixed release: 1.25).
- 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.4 in real deployments (not just unit tests).
- The code incorrectly stripped square brackets from IPv6 addresses, causing an InvalidURL error
- Surfaces as: Error using https and ipv6: InvalidURL("nonnumeric port: '4f7b'",)
Proof / Evidence
- GitHub issue: #707
- Fix PR: https://github.com/urllib3/urllib3/pull/708
- First fixed release: 1.25
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.48
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Wow, our users clearly don't use raw IPv6 addresses very often, or I'd have expected we'd see this sooner”
“Interestingly, this seems to be an artefact of the way http.client behaves. It looks like the square brackets are mandatory:”
“The same problem exists on all versions of Python that I tested, including 3.5 and 2.7.”
“Interestingly, this seems to be in opposition to the comment I can find on connectionpool.py line 71:”
Failure Signature (Search String)
- Error using https and ipv6: InvalidURL("nonnumeric port: '4f7b'",)
Error Message
Stack trace
Error Message
-------------
Error using https and ipv6: InvalidURL("nonnumeric port: '4f7b'",)
Stack trace
Error Message
-------------
Traceback (most recent call last):\n File "/usr/lib/python3.4/http/client.py", line 771, in _set_hostport\n port = int(host[i+1:])
Stack trace
Error Message
-------------
Traceback (most recent call last):\n File "/usr/local/lib/python3.4/dist-packages/urllib3/connectionpool.py", line 548, in urlopen\n conn = self._get_conn(timeout=pool_timeout)\n File "/usr/local/lib/python3.4/dist-packages/urllib3/connectionpool.py", line 250, in _get_conn\n return conn or self._new_conn()\n File "/usr/local/lib/python3.4/dist-packages/urllib3/connectionpool.py", line 770, in _new_conn\n strict=self.strict, **self.conn_kw)\n File "/usr/local/lib/python3.4/dist-packages/urllib3/connection.py", line 171, in __init__\n timeout=timeout, **kw)\n File "/usr/local/lib/python3.4/dist-packages/urllib3/connection.py", line 119, in __init__\n _HTTPConnection.__init__(self, *args, **kw)\n File "/usr/lib/python3.4/http/client.py", line 750, in __init__\n self._set_hostport(host, port)\n File "/usr/lib/python3.4/http/client.py", line 776, in _set_hostport\n raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
Environment
- Python: 3.4
What Broke
Requests to raw IPv6 addresses without ports resulted in connection errors.
Why It Broke
The code incorrectly stripped square brackets from IPv6 addresses, causing an InvalidURL error
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install urllib3==1.25
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/urllib3/urllib3/pull/708
First fixed release: 1.25
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the application relies on the square brackets for other functionality.
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.
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
Version Compatibility Table
| Version | Status |
|---|---|
| 1.25 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.