Jump to solution
Verify

The Fix

pip install requests==2.27.0

Based on closed psf/requests issue #3659 · PR/commit linked

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

Jump to Verify Open PR/Commit
@@ -366,7 +366,7 @@ def proxy_headers(self, proxy): username, password = get_auth_from_url(proxy) - if username and password: + if username: headers['Proxy-Authorization'] = _basic_auth_str(username,
repro.py
import requests from requests.auth import HTTPProxyAuth sess = requests.Session() url1 = 'http://httpbin.org/' url2 = 'http://httpbin.org/redirect/2' auth = HTTPProxyAuth('frank', 'hunter2') proxies = { "http": "http://localhost:9000" } response1 = sess.get(url1, proxies=proxies, auth=auth) response1.raise_for_status() response2 = sess.get(url2, proxies=proxies, auth=auth) response2.raise_for_status()
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 requires both username and non-empty password.\n\n

Why This Fix Works in Production

  • Trigger: response2.raise_for_status()
  • Mechanism: The proxy_headers method fails to emit the auth header when the password is an empty string
  • Why the fix works: [httpAdapter] allows empty password in proxy credentials, fixing the issue where empty passwords do not emit the auth header for redirects. (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 2.7.6 in real deployments (not just unit tests).
  • The proxy_headers method fails to emit the auth header when the password is an empty string
  • Surfaces as: response2.raise_for_status()

Proof / Evidence

  • GitHub issue: #3659
  • Fix PR: https://github.com/psf/requests/pull/3660
  • First fixed release: 2.27.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-07
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.56

Discussion

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

“Aha, ok, so it looks like if there is no password we don't emit auth _at all_ if it comes from the URL. This is…”
@Lukasa · 2016-10-31 · source
“> Out of interest, why on earth do you have a proxy that requires authorization but allows an empty password field? proxy just uses apikey…”
@pawelmhm · 2016-10-31 · source
“> Firstly, HTTPProxyAuth is a backward compatibility auth”
@pawelmhm · 2016-10-31 · source
“That is totally bizarre. Utterly, totally bizarre. But ok. =P I'm happy for us to add a deprecation warning. And we clearly have a bug…”
@Lukasa · 2016-10-31 · source

Failure Signature (Search String)

  • response2.raise_for_status()

Error Message

Stack trace
error.txt
Error Message ------------- response2.raise_for_status() File "----------", line 862, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 407 Client Error: Proxy Authentication Required for url: http://httpbin.org/relative-redirect/1

Minimal Reproduction

repro.py
import requests from requests.auth import HTTPProxyAuth sess = requests.Session() url1 = 'http://httpbin.org/' url2 = 'http://httpbin.org/redirect/2' auth = HTTPProxyAuth('frank', 'hunter2') proxies = { "http": "http://localhost:9000" } response1 = sess.get(url1, proxies=proxies, auth=auth) response1.raise_for_status() response2 = sess.get(url2, proxies=proxies, auth=auth) response2.raise_for_status()

Environment

  • Python: 2.7.6

What Broke

Requests to a proxy with empty password fail with 407 errors on redirects.

Why It Broke

The proxy_headers method fails to emit the auth header when the password is an empty string

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 requires both username and non-empty password.

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/3660

First fixed release: 2.27.0

Last verified: 2026-02-07. 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 requires both username and non-empty password.

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

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

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.