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 HTTPException as error 24 but in the non-Annotated tutorial008d_py310.py. The yield-dependency re-raises InternalError; any item_id other than 'plumbus' returns 404.
Solutions
- Request GET /items/plumbus.
- Understand the tutorial's contrast: this variant re-raises InternalError (500) rather than swallowing it.
- Map InternalError to an HTTPException in the except block if a clean status code is required.
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 != "plumbus":
raise HTTPException(status_code=404, detail=f"Item '{item_id}' not found") Defensive patterns
Strategy: try-catch
Validate before calling
ALLOWED = {'plumbus'}
if item_id not in ALLOWED:
print('404; portal-gun -> 500') 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('unknown id')
elif resp.status_code == 500:
print('re-raised InternalError') Prevention
- Use Annotated form for new code (tutorial008d_an).
- Translate InternalError to HTTPException for clean status codes.
- Test both failure paths explicitly.
When it happens
Trigger: GET /items/{item_id} with item_id != 'plumbus' and != 'portal-gun'.
Common situations: Testing the re-raise variant of yield-dependencies. The 404 fires for ordinary unknown ids; the InternalError (500) fires for 'portal-gun'.
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/48a554ee92d6b27f.
Report an issue: GitHub.
Appendix: source
Thrown at docs_src/dependencies/tutorial008d_py310.py:25
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("We don't swallow the internal error here, we raise again 😎")
raise
@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)