python
auth_error
ai_generated
true
fastapi.exceptions.HTTPException: 401 未授权:{"detail":"未认证"}
fastapi.exceptions.HTTPException: 401 Unauthorized: {"detail":"Not authenticated"}
ID: python/fastapi-oauth2-token-missing
80%修复率
88%置信度
0证据数
2024-06-28首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
根因分析
Authorization 头缺失或格式错误,导致 OAuth2PasswordBearer 依赖在到达路由前拒绝了请求。
English
The Authorization header was missing or malformed, so the OAuth2PasswordBearer dependency rejected the request before reaching the route.
解决方案
-
95% 成功率
fetch('/me', {headers: {'Authorization': `Bearer ${token}`}}) -
85% 成功率
def get_token(request: Request): return request.cookies.get('access_token')
无效尝试
常见但无效的做法:
-
80% 失败
Route then receives None token and crashes on decode.
-
90% 失败
Auth bypass ships to production; security hole.