python type_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-07-07First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 50% fail

    This is not standard and may break URL encoding.

  2. 70% fail

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