Jump to solution
Verify

The Fix

pip install requests==2.27.0

Based on closed psf/requests issue #4353 · 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%.

Jump to Verify Open PR/Commit
@@ -180,3 +180,4 @@ Patches and Suggestions - Taylor Hoff <[email protected]> (`@PrimordialHelios <https://github.com/PrimordialHelios>`_) - Arthur Vigil (`@ahvigil <https://github.com/ahvigil>`_) +- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_) diff --git a/HISTORY.rst b/HISTORY.rst index e6281c1e77..79202df646 100644
repro.py
(req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128 (req2) nwani@dockerub01:~/requests$ python -c "import requests; requests.get('https://google.com')" Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/nehaljwani/requests/requests/api.py", line 72, in get return request('get', url, params=params, **kwargs) File "/home/nehaljwani/requests/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/home/nehaljwani/requests/requests/adapters.py", line 440, in send timeout=timeout File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 595, in urlopen self._prepare_proxy(conn) File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 816, in _prepare_proxy conn.connect() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 284, in connect conn = self._new_conn() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 51, in create_connection if host.startswith('['): AttributeError: 'NoneType' object has no attribute 'startswith'
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install requests==2.27.0\nWhen NOT to use: This fix is not applicable if the proxy URL is intentionally malformed.\n\n

Why This Fix Works in Production

  • Trigger: (req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128
  • Mechanism: The proxy URL was malformed due to a missing '/' in the protocol, causing an AttributeError
  • Why the fix works: Adds a check to verify that the parsed proxy URL has a valid host before creating the proxy manager, addressing the misleading exception issue. (first fixed release: 2.27.0).
Production impact:
  • 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.6 in real deployments (not just unit tests).
  • The proxy URL was malformed due to a missing '/' in the protocol, causing an AttributeError
  • Surfaces as: (req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128

Proof / Evidence

  • GitHub issue: #4353
  • Fix PR: https://github.com/psf/requests/pull/4356
  • First fixed release: 2.27.0
  • 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.30

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“On dumping the connection object right before calling conn.urlopen(), the output for print(vars(conn)) reveals: And this makes urllib3 think that the proxy to be reached…”
@nehaljwani · 2017-10-23 · source
“requests calls prepend_scheme_if_needed() in the function get_connection() and in this case changes the url to http:///my.proxy.com:3128 ... which when passed to parse_url() from urllib3.util: ...…”
@nehaljwani · 2017-10-23 · source
“Sure, but semantically speaking, an empty authority section doesn't make sense for a proxy URI right?”
@nehaljwani · 2017-10-23 · source
“@nehaljwani exactly. This is why I suggest checking for that and raising a more helpful/understandable exception.”
@sigmavirus24 · 2017-10-23 · source

Failure Signature (Search String)

  • (req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128

Error Message

Stack trace
error.txt
Error Message ------------- (req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128 (req2) nwani@dockerub01:~/requests$ python -c "import requests; requests.get('https://google.com')" Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/nehaljwani/requests/requests/api.py", line 72, in get return request('get', url, params=params, **kwargs) File "/home/nehaljwani/requests/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/home/nehaljwani/requests/requests/adapters.py", line 440, in send timeout=timeout File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 595, in urlopen self._prepare_proxy(conn) File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 816, in _prepare_proxy conn.connect() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 284, in connect conn = self._new_conn() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/ ... (truncated) ...

Minimal Reproduction

repro.py
(req2) nwani@dockerub01:~/requests$ export https_proxy=http:/my.proxy.com:3128 (req2) nwani@dockerub01:~/requests$ python -c "import requests; requests.get('https://google.com')" Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/nehaljwani/requests/requests/api.py", line 72, in get return request('get', url, params=params, **kwargs) File "/home/nehaljwani/requests/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/home/nehaljwani/requests/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/home/nehaljwani/requests/requests/adapters.py", line 440, in send timeout=timeout File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 595, in urlopen self._prepare_proxy(conn) File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 816, in _prepare_proxy conn.connect() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 284, in connect conn = self._new_conn() File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/home/nehaljwani/m3/envs/req2/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 51, in create_connection if host.startswith('['): AttributeError: 'NoneType' object has no attribute 'startswith'

Environment

  • Python: 3.6

What Broke

Users experienced misleading exceptions when using an invalid proxy configuration.

Why It Broke

The proxy URL was malformed due to a missing '/' in the protocol, causing an AttributeError

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install requests==2.27.0

When NOT to use: This fix is not applicable if the proxy URL is intentionally malformed.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/psf/requests/pull/4356

First fixed release: 2.27.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the proxy URL is intentionally malformed.

Verify Fix

verify
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 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.
  • 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

VersionStatus
2.27.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.