python
runtime_error
ai_generated
true
fastapi.exceptions.HTTPException: 404 Not Found
ID: python/fastapi-http-exception-handler
80%Fix Rate
84%Confidence
0Evidence
2024-07-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
请求的 URL 路径不存在或未定义路由。
generic中文
请求的 URL 路径不存在或未定义路由。
Workarounds
-
95% success
@app.exception_handler(404) async def not_found_handler(request, exc): return JSONResponse(status_code=404, content={'message': 'Not Found'})
Dead Ends
Common approaches that don't work:
-
70% fail
会隐藏真正的 404 错误,导致客户端困惑
-
90% fail
会拦截所有请求,导致其他路由失效