Gunicorn 'Application Object Must Be Callable' 错误

Gunicorn 'Application Object Must Be Callable' error

我正在尝试使用 gunicorn 和 nginx 部署一个用 Dash 编写的应用程序。几个月前,当我知道自己在做什么时,我成功部署了同一个应用程序。我想进行一些更新并重新部署,但现在部署无法正常工作,即使我删除所有更新也是如此。当我 运行 gunicorn 时,我得到一个错误,Application must be callable

我在 folder 中有我的项目,其中包含 unified.py 文件,其中有我的应用程序。在 unified.pyapp = dash.Dash(__name__, external_stylesheets=external_stylesheets) 中,我将我的应用程序变量定义为 app.

I 运行 gunicorn folder.unified:app 并得到这个错误。 但是,如果我 运行 from folder.unified import app 我得到应用程序对象和所有适当的属性,没问题。

我尝试了 gunicorn 调用的各种变体(例如在项目文件夹中并说 gunicornunified:app, being the parent folder and usinggunicorn folder:app, gunicorn folder:unified`。我知道它可以工作,因为它以前工作过。但对于我来说,我无法弄清楚现在发生了什么。

我希望它 运行 与我 运行 使用 python 使用 python unified.py 的应用程序类似。

有一段时间我认为我已经解决了它,因为我开始收到一个不同的错误(说我无法从另一个文件夹中获取 .pkl 文件),但后来我在 [=13] 中注释掉了这些行=] 文件,它返回到相同的 Application must be callable 错误!

gunicorn unified:app.server

我在 Plotly 论坛上找到解决方案的交叉参考: https://community.plot.ly/t/error-with-gunicorn/8247

在主代码中定义应用程序后添加服务器。 (例如:main.py)

app=dash.Dash(__name__)   
server=app.server

然后 运行 终端中的 gunicorn

gunicorn main:server

如果您想通过 LAN 访问并设置端口和工作人员

gunicorn -w 4 -b 0.0.0.0:4000 app_test:server