python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: Request 出现 1 个验证错误 query -> ids.0 值不是有效的整数 (type=type_error.integer)
fastapi.exceptions.RequestValidationError: 1 validation error for Request query -> ids.0 value is not a valid integer (type=type_error.integer)
ID: python/fastapi-query-param-list-parsing
80%修复率
86%置信度
0证据数
2024-05-27首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
客户端发送了重复查询参数(ids=1&ids=2),但端点声明 ids: List[int] 使用了旧版 FastAPI,或使用了不被解析的 ids[]=1。
English
Client sent repeated query parameters (ids=1&ids=2) but the endpoint declared ids: List[int] with an older FastAPI or used ids[]=1 which is not parsed.
解决方案
-
92% 成功率
Declare ids: List[int] = Query(default=[]) and send ids=1&ids=2
-
88% 成功率
Use a JSON body model with ids: List[int] instead of query params
无效尝试
常见但无效的做法:
-
55% 失败
Loses validation and OpenAPI schema.
-
70% 失败
FastAPI does not strip brackets by default.