python
runtime_error
ai_generated
true
RuntimeError: 未找到应用。可能忘记传递 app,或在应用创建前尝试访问。
RuntimeError: No application found. Either you forgot to pass an app, or you tried to access the app before it was created.
ID: python/starlette-runtime-error
80%修复率
85%置信度
0证据数
2024-03-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
Starlette 应用实例未正确初始化或未传递给服务器。
English
Starlette 应用实例未正确初始化或未传递给服务器。
解决方案
-
95% 成功率
确保应用实例在模块级别定义,并正确传递给 uvicorn。
-
90% 成功率
使用 uvicorn.run(app, host='0.0.0.0', port=8000)。
-
85% 成功率
检查导入语句,确保路径正确。
无效尝试
常见但无效的做法:
-
80% 失败
在模块级别访问 app,但应用在函数内创建。
-
70% 失败
忘记在 uvicorn 中传递 app 对象。
-
60% 失败
使用错误的导入路径。