Jump to solution
Verify

The Fix

Fixes the handling of redirects with authentication, ensuring that users will no longer receive a ValueError when encountering multiple authenticated URLs in a redirect chain.

Based on closed aio-libs/aiohttp issue #9436 · 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
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Authentication provided by a redirect now takes precedence over provided ``auth`` when making requests with the client -- by :user:`PLPeeters`. diff --git a/aiohttp/client.py b/aiohttp/client.py index 343d20436e7..15c89018ffb 100644
repro.py
import aiohttp import asyncio async def main(): async with aiohttp.ClientSession() as session: await session.get('http://itheka.gr', allow_redirects=True) if __name__ == "__main__": asyncio.run(main())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Apply the official fix\nFixes the handling of redirects with authentication, ensuring that users will no longer receive a ValueError when encountering multiple authenticated URLs in a redirect chain.\nWhen NOT to use: This fix is not applicable if the redirect behavior is intentionally designed to raise ValueError.\n\n

Why This Fix Works in Production

  • Trigger: >> import aiohttp
  • Mechanism: The client incorrectly raises a ValueError instead of TooManyRedirects for authenticated redirects
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.12 in real deployments (not just unit tests).
  • The client incorrectly raises a ValueError instead of TooManyRedirects for authenticated redirects
  • Surfaces as: >> import aiohttp

Proof / Evidence

Discussion

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

“I don't think that check should be happening on redirects, only on the original url parameter. So, option 2. I'm also wondering if we should…”
@Dreamsorcerer · 2024-10-09 · source
“It probably makes sense to just move that check to somewhere before the loop.”
@Dreamsorcerer · 2024-10-09 · source

Failure Signature (Search String)

  • >> import aiohttp

Error Message

Stack trace
error.txt
Error Message ------------- >> import aiohttp >> import asyncio >> >> >> async def main(): ... async with aiohttp.ClientSession() as session: ... await session.get('http://itheka.gr', allow_redirects=True) ... >> >> if __name__ == "__main__": ... asyncio.run(main()) ... Traceback (most recent call last): File "<stdin>", line 2, in <module> File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "<stdin>", line 3, in main File "/Users/peetersp/Documents/Swan/website-processors/venv/lib/python3.12/site-packages/aiohttp/client.py", line 591, in _request raise ValueError( ValueError: Cannot combine AUTH argument with credentials encoded in URL

Minimal Reproduction

repro.py
import aiohttp import asyncio async def main(): async with aiohttp.ClientSession() as session: await session.get('http://itheka.gr', allow_redirects=True) if __name__ == "__main__": asyncio.run(main())

Environment

  • Python: 3.12

What Broke

Users experience unexpected ValueError when following authenticated redirects.

Why It Broke

The client incorrectly raises a ValueError instead of TooManyRedirects for authenticated redirects

Fix Options (Details)

Option A — Apply the official fix

Fixes the handling of redirects with authentication, ensuring that users will no longer receive a ValueError when encountering multiple authenticated URLs in a redirect chain.

When NOT to use: This fix is not applicable if the redirect behavior is intentionally designed to raise ValueError.

Fix reference: https://github.com/aio-libs/aiohttp/pull/9443

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 redirect behavior is intentionally designed to raise ValueError.

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

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

Related Issues

No related fixes found.

Sources

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