python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: [{'loc': ['query', 'page'], 'msg': 'field required', 'type': 'value_error.missing'}]
ID: python/fastapi-query-param-missing
80%Fix Rate
90%Confidence
0Evidence
2024-10-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A required query parameter is not provided in the request URL.
generic中文
请求 URL 中未提供必需的查询参数。
Workarounds
-
95% success
Provide a default value: def read_items(page: int = 1)
-
90% success
Make it optional with Optional[int] = None and handle None in the function
Dead Ends
Common approaches that don't work:
-
30% fail
If the default is set, FastAPI won't raise an error; the error occurs only when no default is given.
-
60% fail
This handles the error but doesn't fix the missing parameter; the client still needs to send it.