python
runtime_error
ai_generated
true
AttributeError: 'FastAPI' object has no attribute 'router'
ID: python/fastapi-attribute-error-router
80%Fix Rate
85%Confidence
0Evidence
2024-11-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Calling app.router incorrectly or using an older API pattern where the router attribute is accessed on a non-app object.
generic中文
错误地调用 app.router,或在非应用对象上访问 router 属性的旧 API 模式。
Workarounds
-
94% success
from fastapi import APIRouter router = APIRouter() app.include_router(router)
-
88% success
for r in app.routes: print(r.path)
Dead Ends
Common approaches that don't work:
-
85% fail
Attribute name exists but internal structure differs; downstream calls fail.
-
80% fail
Reintroduces other incompatibilities and is unsupported.