python config_error ai_generated true

值错误:未知的路径转换器 'int'

ValueError: Unknown path converter 'int'

ID: python/starlette-route-param-converter

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2026-05-15首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

使用了 Starlette 不支持的路径转换器,如 int 但语法不正确。

English

Using a path converter that Starlette doesn't support, such as int without proper syntax.

generic

解决方案

  1. 100% 成功率
    Use the correct syntax: @app.route('/items/{item_id:int}')
  2. 95% 成功率
    In FastAPI, use type annotation: @app.get('/items/{item_id}') with item_id: int

无效尝试

常见但无效的做法:

  1. 70% 失败

    Starlette uses {item_id:int} syntax, but it must be exactly that; if you use {item_id} with a type annotation, it's different.

  2. 30% 失败

    The converter is built-in; no import needed.