# fastapi.exceptions.RequestValidationError: 请求出现 1 个验证错误
query -> page
  输入应为有效整数，无法将字符串解析为整数

- **ID:** `python/fastapi-request-validation-query`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

声明为 int 的查询参数收到了客户端传来的非数字字符串（通常是空值或 'abc'）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   from fastapi import Query
@app.get('/items')
async def items(page: int = Query(1, ge=1)): ...
   ```
2. **** (85% 成功率)
   ```
   @app.exception_handler(RequestValidationError)
async def handler(req, exc):
    return JSONResponse(status_code=422, content={'errors': exc.errors()})
   ```

## 无效尝试

- **** — Clients keep sending bad data and pagination logic receives None. (85% 失败率)
- **** — Moves the failure to an uncaught ValueError deeper in the stack. (70% 失败率)
