# fastapi.exceptions.HTTPException: 401 未授权：{"detail":"未认证"}

- **ID:** `python/fastapi-oauth2-token-missing`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Authorization 头缺失或格式错误，导致 OAuth2PasswordBearer 依赖在到达路由前拒绝了请求。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   fetch('/me', {headers: {'Authorization': `Bearer ${token}`}})
   ```
2. **** (85% 成功率)
   ```
   def get_token(request: Request):
    return request.cookies.get('access_token')
   ```

## 无效尝试

- **** — Route then receives None token and crashes on decode. (80% 失败率)
- **** — Auth bypass ships to production; security hole. (90% 失败率)
