# fastapi.exceptions.HTTPException: 405 Method Not Allowed

- **ID:** `python/fastapi-cors-error`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

CORS 配置不正确，或请求方法未在路由中允许。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   添加 CORSMiddleware 并允许所有来源、方法、头。
   ```
2. **** (95% success)
   ```
   确保路由装饰器包含正确的 HTTP 方法。
   ```
3. **** (85% success)
   ```
   为 OPTIONS 请求添加自动处理。
   ```

## Dead Ends

- **** — 尝试在前端修改请求方法，但后端不允许。 (60% fail)
- **** — 忽略 OPTIONS 预检请求。 (80% fail)
- **** — 使用错误的 CORS 中间件参数。 (70% fail)
