python runtime_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-03-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Starlette 应用实例未正确初始化或未传递给服务器。

generic

中文

Starlette 应用实例未正确初始化或未传递给服务器。

Workarounds

  1. 95% success
    确保应用实例在模块级别定义,并正确传递给 uvicorn。
  2. 90% success
    使用 uvicorn.run(app, host='0.0.0.0', port=8000)。
  3. 85% success
    检查导入语句,确保路径正确。

Dead Ends

Common approaches that don't work:

  1. 80% fail

    在模块级别访问 app,但应用在函数内创建。

  2. 70% fail

    忘记在 uvicorn 中传递 app 对象。

  3. 60% fail

    使用错误的导入路径。