# HTTP异常：405 方法不允许

- **ID:** `python/starlette-http-405-method-not-allowed`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用的HTTP方法不允许用于请求的端点。

## 版本兼容性

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

## 解决方案

1. **Check the allowed methods for the endpoint and use the correct one.** (95% 成功率)
   ```
   Check route: @app.route('/items', methods=['GET'])
   ```
2. **Add the missing method to the route decorator.** (90% 成功率)
   ```
   @app.route('/items', methods=['GET', 'POST'])
   ```

## 无效尝试

- **Assuming all methods are allowed by default.** — Routes are defined with specific methods; others are rejected. (80% 失败率)
- **Using POST instead of GET without checking the endpoint definition.** — The endpoint may only accept GET requests. (70% 失败率)
