# fastapi.exceptions.HTTPException: 404: Not Found

- **ID:** `python/fastapi-http-exception-404-not-found`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Requested URL path does not match any defined route in the FastAPI application.

## Version Compatibility

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

## Workarounds

1. **Check and correct the route definition** (95% success)
   ```
   @app.get('/items/{item_id}')
async def read_item(item_id: int):
    return {'item_id': item_id}
# Access /items/123, not /items/
   ```
2. **Add a custom 404 handler for better debugging** (90% success)
   ```
   @app.exception_handler(404)
async def not_found_handler(request, exc):
    return JSONResponse(status_code=404, content={'message': 'Route not found'})
   ```

## Dead Ends

- **Adding a catch-all route that returns 200** — Masks real errors and may cause unintended behavior. (60% fail)
- **Assuming trailing slash mismatch** — FastAPI by default does not redirect, so /users and /users/ are different. (50% fail)
