python
auth_error
ai_generated
true
fastapi.exceptions.HTTPException: 401 Unauthorized: {"detail":"Not authenticated"}
ID: python/fastapi-oauth2-token-missing
80%Fix Rate
88%Confidence
0Evidence
2024-06-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
Root Cause
The Authorization header was missing or malformed, so the OAuth2PasswordBearer dependency rejected the request before reaching the route.
generic中文
Authorization 头缺失或格式错误,导致 OAuth2PasswordBearer 依赖在到达路由前拒绝了请求。
Workarounds
-
95% success
fetch('/me', {headers: {'Authorization': `Bearer ${token}`}}) -
85% success
def get_token(request: Request): return request.cookies.get('access_token')
Dead Ends
Common approaches that don't work:
-
80% fail
Route then receives None token and crashes on decode.
-
90% fail
Auth bypass ships to production; security hole.