python
auth_error
ai_generated
true
fastapi.exceptions.HTTPException: 401 Unauthorized: {"detail":"Not authenticated"}
ID: python/fastapi-oauth2-missing-token
80%Fix Rate
88%Confidence
0Evidence
2025-01-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
Root Cause
OAuth2PasswordBearer dependency did not receive an Authorization: Bearer header, or the token was rejected.
generic中文
OAuth2PasswordBearer依赖未收到Authorization: Bearer头,或token被拒绝。
Workarounds
-
95% success
headers = {'Authorization': f'Bearer {token}'}\nrequests.get(url, headers=headers) -
90% success
from fastapi.security import HTTPBearer\nsecurity = HTTPBearer(auto_error=False)
Dead Ends
Common approaches that don't work:
-
80% fail
Returns None token and downstream logic still fails.
-
85% fail
OAuth2PasswordBearer expects the Authorization header by default.