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
Same 404 "Item not found, there's only a plumbus here" as error 24, in the non-Annotated Depends style. Raised when item_id is not "plumbus" and not "portal-gun".
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 42a41db11f)
Solutions
- Call /items/plumbus.
- Document the allowed id set and validate input early.
- Keep 404 detail text consistent across endpoints.
- Test the negative path.
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=f"Unknown item '{item_id}'") Defensive patterns
Strategy: validation
Validate before calling
if item_id not in {"plumbus", "portal-gun"}:
raise ValueError("unsupported item id") Type guard
def is_known_item(item_id: str) -> bool:
return item_id in {"plumbus", "portal-gun"} Try / catch
r = client.get(f"/items/{item_id}")
if r.status_code == 404:
... Prevention
- Validate the id client-side before calling.
- Treat the whimsical 404 detail as informative, not authoritative.
- Keep Annotated/non-Annotated endpoints behaviorally identical.
When it happens
Trigger: GET /items/<not-plumbus-and-not-portal-gun> using the default-value Depends form of the endpoint.
Common situations: Same as error 24; encountered when the older tutorial variant is in use.
Related errors
- Item not found
- 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
- Item not found
AI-assisted analysis of tiangolo/fastapi@42a41db11f (2026-08-04).
Data as JSON: /data/errors/061107824f7ddefa.json.
Report an issue: GitHub.