python
runtime_error
ai_generated
true
fastapi.HTTPException: 404 Not Found
ID: python/fastapi-httpexception-not-found
80%Fix Rate
87%Confidence
0Evidence
2024-06-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Requested URL does not match any defined route.
generic中文
请求的URL与任何定义的路由不匹配。
Workarounds
-
90% success Verify URL and method match a route
Check app routes: for route in app.routes: print(route.path, route.methods)
-
80% success Add a catch-all route for debugging
@app.api_route('/{path:path}', methods=['GET', 'POST']) async def catch_all(path: str): return {'path': path}
Dead Ends
Common approaches that don't work:
-
Assuming trailing slash doesn't matter
50% fail
FastAPI distinguishes between /path and /path/ unless configured.
-
Using wrong HTTP method
70% fail
Route may exist but not for the used method (e.g., POST vs GET).