繁体   English   中英

Python 带女服务员的 Dash 服务器

[英]Python Dash server with waitress

我有一个用 Dash 框架编写的仪表板应用程序。 它还有一些使用 flask 编写的 Restful API。 我将 flask 应用程序添加到 Dash 服务器,如

import dash
import flask
import dash_bootstrap_components as dbc

flask_server = flask.Flask(__name__)
app = dash.Dash(__name__,server=flask_server, external_stylesheets=[dbc.themes.BOOTSTRAP])

并将服务器运行为

from dashboard import app
from waitress import serve

if __name__ == "__main__":
    app.title = 'Litmus'
    app.run_server(debug=False)
    # serve(app,host="0.0.0.0",port=8050)

上面的代码在我使用app.run_server(debug=False)时工作正常,但是当我使用 waitress 运行服务器时它会抛出异常。 当我使用以下几行

#app.run_server(debug=False)
serve(app,host="0.0.0.0",port=8050)

我收到以下错误

ERROR:waitress:Exception while serving /
Traceback (most recent call last):
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
    task.service()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
    self.execute()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable
ERROR:waitress:Exception while serving /favicon.ico
Traceback (most recent call last):
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\channel.py", line 397, in service
    task.service()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 168, in service
    self.execute()
  File "C:\Users\litmus\AppData\Roaming\Python\Python38\site-packages\waitress\task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
TypeError: 'Dash' object is not callable

它不起作用,因为您传递的是 Dash 应用程序而不是 Flask 应用程序来serve

所以代替这个:

serve(app,host="0.0.0.0",port=8050)

像这样传递 Flask 应用程序实例:

serve(app.server, host="0.0.0.0", port=8050)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM