tiangolo/fastapi · error · HTTPException
Item not found, there's only a plumbus here
Error message
Item not found, there's only a plumbus here
What it means
Identical logic to error 22 but in the non-Annotated tutorial008c_py310.py (uses `username: str = Depends(get_username)` instead of Annotated). Same 404 HTTPException for any item_id other than 'plumbus'. The InternalError path for 'portal-gun' is swallowed by the dependency's except block.
Solutions
- Request GET /items/plumbus.
- Recognize the tutorial's point: a yield-dependency that catches but does not re-raise will swallow InternalError, so unknown ids simply 404.
- Switch to the re-raise pattern (tutorial008d) if you want the InternalError to surface.
Example fix
// before
if item_id != "plumbus":
raise HTTPException(status_code=404, detail="Item not found, there's only a plumbus here")
// after
if item_id not in ("plumbus",):
raise HTTPException(status_code=404, detail="Item not found, there's only a plumbus here") Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'plumbus'}
assert item_id in ALLOWED Type guard
def is_known_item(item_id: str) -> bool:
return item_id == 'plumbus' Try / catch
resp = requests.get(f'http://localhost:8000/items/{item_id}')
if resp.status_code == 404:
print('404: only plumbus is valid') Prevention
- Use the re-raise variant if you need InternalError to surface.
- Keep the allowed-id set documented.
- Distinguish swallowed-vs-raised failure modes in tests.
When it happens
Trigger: GET /items/{item_id} with item_id != 'plumbus' and != 'portal-gun'.
Common situations: Same as the Annotated variant; difference is purely the dependency-injection syntax. Hit when clients guess item ids outside the allowed single-element set.
Related errors
- Item not found, there's only a plumbus here
- Item not found, there's only a plumbus here
- Item not found, there's only a plumbus here
- Hero not found
- Hero not found
AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11).
Data as JSON: /api/errors/061107824f7ddefa.
Report an issue: GitHub.
Appendix: source
Thrown at docs_src/dependencies/tutorial008c_py310.py:24
class InternalError(Exception):
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("Oops, we didn't raise again, Britney 😱")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: str = Depends(get_username)):
if item_id == "portal-gun":
raise InternalError(
f"The portal gun is too dangerous to be owned by {username}"
)
if item_id != "plumbus":
raise HTTPException(
status_code=404, detail="Item not found, there's only a plumbus here"
)
return item_id
View on GitHub (pinned to 3e8d1526d8)