python
type_error
ai_generated
true
AssertionError: 缺少必需的查询参数'page'
AssertionError: Query parameter 'page' is required
ID: python/starlette-missing-query-param
80%修复率
82%置信度
0证据数
2024-10-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
路由处理器期望查询参数,但请求中不存在该参数。
English
The route handler expects a query parameter that is not present in the request.
解决方案
-
95% 成功率
Use Query parameter with default: page: int = Query(1, ge=1)
-
90% 成功率
Check for existence and provide a fallback: page = request.query_params.get('page', 1)
无效尝试
常见但无效的做法:
-
80% 失败
This raises a TypeError when page is None.
-
50% 失败
Empty string may still be invalid.