# ImportError: cannot import name 'HTTPException' from 'fastapi'

- **ID:** `python/fastapi-missing-starlette-import`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

HTTPException is actually from starlette, not fastapi directly in some versions.

## Version Compatibility

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

## Workarounds

1. **Import HTTPException from starlette instead.** (95% success)
   ```
   from starlette.exceptions import HTTPException
   ```
2. **Use fastapi's HTTPException if available; check version.** (85% success)
   ```
   from fastapi import HTTPException  # Works in recent versions
   ```

## Dead Ends

- **Installing an older version of fastapi that has HTTPException.** — The import path may have changed; older versions may still have it. (50% fail)
- **Assuming it's a bug and reinstalling fastapi.** — Reinstalling may not fix the import path issue. (60% fail)
