python
runtime_error
ai_generated
true
AttributeError: 'FastAPI' 对象没有属性 'router'
AttributeError: 'FastAPI' object has no attribute 'router'
ID: python/fastapi-attribute-error-router
80%修复率
85%置信度
0证据数
2024-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
错误地调用 app.router,或在非应用对象上访问 router 属性的旧 API 模式。
English
Calling app.router incorrectly or using an older API pattern where the router attribute is accessed on a non-app object.
解决方案
-
94% 成功率
from fastapi import APIRouter router = APIRouter() app.include_router(router)
-
88% 成功率
for r in app.routes: print(r.path)
无效尝试
常见但无效的做法:
-
85% 失败
Attribute name exists but internal structure differs; downstream calls fail.
-
80% 失败
Reintroduces other incompatibilities and is unsupported.