python type_error ai_generated true

AssertionError: 缺少必需的查询参数'page'

AssertionError: Query parameter 'page' is required

ID: python/starlette-missing-query-param

其他格式: JSON · Markdown 中文 · English
80%修复率
82%置信度
0证据数
2024-10-22首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

路由处理器期望查询参数,但请求中不存在该参数。

English

The route handler expects a query parameter that is not present in the request.

generic

解决方案

  1. 95% 成功率
    Use Query parameter with default: page: int = Query(1, ge=1)
  2. 90% 成功率
    Check for existence and provide a fallback: page = request.query_params.get('page', 1)

无效尝试

常见但无效的做法:

  1. 80% 失败

    This raises a TypeError when page is None.

  2. 50% 失败

    Empty string may still be invalid.