# fastapi.exceptions.HTTPException: 401 未授权：未认证

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

## 根因

OAuth2PasswordBearer依赖未收到Authorization: Bearer头，或token被拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100.x | active | — | — |
| 0.110.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   headers = {'Authorization': f'Bearer {token}'}\nrequests.get(url, headers=headers)
   ```
2. **** (90% 成功率)
   ```
   from fastapi.security import HTTPBearer\nsecurity = HTTPBearer(auto_error=False)
   ```

## 无效尝试

- **** — Returns None token and downstream logic still fails. (80% 失败率)
- **** — OAuth2PasswordBearer expects the Authorization header by default. (85% 失败率)
