# FastAPI HTTP异常：404未找到

- **ID:** `python/fastapi-httpexception-not-found`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求的URL与任何定义的路由不匹配。

## 版本兼容性

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

## 解决方案

1. **Verify URL and method match a route** (90% 成功率)
   ```
   Check app routes: for route in app.routes: print(route.path, route.methods)
   ```
2. **Add a catch-all route for debugging** (80% 成功率)
   ```
   @app.api_route('/{path:path}', methods=['GET', 'POST'])
async def catch_all(path: str):
    return {'path': path}
   ```

## 无效尝试

- **Assuming trailing slash doesn't matter** — FastAPI distinguishes between /path and /path/ unless configured. (50% 失败率)
- **Using wrong HTTP method** — Route may exist but not for the used method (e.g., POST vs GET). (70% 失败率)
