python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]
ID: python/fastapi-path-param-type-error
80%Fix Rate
87%Confidence
0Evidence
2025-04-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A path parameter annotated as int receives a non-integer value from the URL.
generic中文
路径参数标注为 int,但 URL 中提供了非整数值。
Workarounds
-
90% success
Ensure the client sends an integer in the URL, e.g., /items/123
-
100% success
Use a Pydantic model or path converter: @app.get('/items/{item_id}') with item_id: int
Dead Ends
Common approaches that don't work:
-
60% fail
This doesn't fix the client's request; they still need to send a valid integer.
-
50% fail
Loses automatic validation; you have to handle conversion errors yourself.