# starlette.exceptions.HTTPException：401: 未授权

- **ID:** `python/starlette-httpexception-401`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

身份验证凭据缺失或无效。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.30.x | active | — | — |
| 0.40.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   headers = {'Authorization': f'Bearer {token}'}
   ```
2. **** (90% 成功率)
   ```
   If 401, use refresh token to get a new access token.
   ```

## 无效尝试

- **** — Exposes protected endpoints. (90% 失败率)
- **** — Security risk. (95% 失败率)
