python data_error ai_generated true

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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.

generic

中文

客户端发送了重复查询参数(ids=1&ids=2),但端点声明 ids: List[int] 使用了旧版 FastAPI,或使用了不被解析的 ids[]=1。

Workarounds

  1. 92% success
    Declare ids: List[int] = Query(default=[]) and send ids=1&ids=2
  2. 88% success
    Use a JSON body model with ids: List[int] instead of query params

Dead Ends

Common approaches that don't work:

  1. 55% fail

    Loses validation and OpenAPI schema.

  2. 70% fail

    FastAPI does not strip brackets by default.