python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: value is not a valid integer
ID: python/fastapi-query-parameter-validation
80%Fix Rate
83%Confidence
0Evidence
2024-09-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
查询参数或路径参数的类型不匹配,例如传入了字符串而不是整数。
generic中文
查询参数或路径参数的类型不匹配,例如传入了字符串而不是整数。
Workarounds
-
100% success
@app.get('/items/{item_id}') async def get_item(item_id: int): return {'item_id': item_id}
Dead Ends
Common approaches that don't work:
-
90% fail
FastAPI 会在函数执行前验证,转换无效
-
80% fail
会忽略验证错误,导致数据不一致