python
network_error
ai_generated
true
HTTPException: 308 Permanent Redirect: Redirect loop detected
ID: python/starlette-http-redirect-loop
80%Fix Rate
83%Confidence
0Evidence
2025-03-25First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
Root Cause
Starlette 应用中的重定向配置导致无限循环
generic中文
Starlette 应用中的重定向配置导致无限循环
Workarounds
-
90% success 检查并修复重定向逻辑
# 确保不重定向到自身 if request.url.path != '/target': return RedirectResponse('/target') -
85% success 使用条件重定向避免循环
if not request.cookies.get('redirected'): response = RedirectResponse('/target') response.set_cookie('redirected', '1') return response
Dead Ends
Common approaches that don't work:
-
增加重定向次数限制但未修复逻辑
70% fail
最终仍会失败,且用户体验差
-
删除所有重定向路由
60% fail
可能破坏应用功能