python type_error ai_generated true

fastapi.exceptions.RequestValidationError: [{'loc': ['query', 'tags'], 'msg': '值不是有效的列表', 'type': 'type_error.list'}]

fastapi.exceptions.RequestValidationError: [{'loc': ['query', 'tags'], 'msg': 'value is not a valid list', 'type': 'type_error.list'}]

ID: python/fastapi-query-param-list-error

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

版本兼容性

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

根因分析

查询参数声明为 List[str],但客户端发送单个字符串而未重复参数。

English

A query parameter is declared as List[str] but the client sends a single string without repeated parameters.

generic

解决方案

  1. 100% 成功率
    Send multiple query parameters: /path?tags=a&tags=b
  2. 80% 成功率
    Use a string and parse it: tags: str = Query(""), then tags.split(",")

无效尝试

常见但无效的做法:

  1. 50% 失败

    This is not standard and may break URL encoding.

  2. 70% 失败

    The validation still fails because the value is not a list.