# 类型错误：'str'对象无法解释为整数

- **ID:** `python/starlette-route-parameter-type-mismatch`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

预期为整数的路由参数以字符串形式传递，未进行转换。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Convert the parameter to int explicitly** (90% 成功率)
   ```
   async def get_item(item_id: str):
    item_id = int(item_id)
   ```
2. **Use Starlette's path converter for int** (95% 成功率)
   ```
   @app.route('/items/{item_id:int}')
async def get_item(item_id: int):
    ...
   ```

## 无效尝试

- **Using str() on the parameter** — Doesn't convert to int; keeps it as string. (80% 失败率)
- **Ignoring the type and using the string directly** — May cause errors in logic expecting an integer. (70% 失败率)
