部署在 apache 服务器上的 Dash 失败 "Dash object not callable"
Dash deployed on apache server failing with "Dash object not callable"
我正在尝试将 python dash 应用程序部署到我的 apache 服务器。我遵循了我能找到的有关此配置的少量信息 (officials docs; this troubleshooting thread was a bit better)。当我访问该网站时,页面 returns 变成 500 Internal Server Error
,在服务器错误日志中被描述为 "Dash object not callable"
。这些是配置文件:
>> cat /var/www/html/wsgi/dashGAF.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/home/ubuntu/dashboards/")
from dashGAF import app as application
>> cat /etc/apache2/sites-available/dash.conf
WSGIDaemonProcess dashGAF user=ubuntu group=ubuntu home=/home/ubuntu threads=5
WSGIScriptAlias /dashGAF /var/www/html/wsgi/dashGAF.wsgi
<Directory /home/ubuntu/dashboards>
WSGIProcessGroup dashGAF
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
>> cat dashGAF.py
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, routes_pathname_prefix='/dashGAF/')
server = app.server
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0')
当我在 the_ip_address/dashGAF
访问我的 dash 应用程序时,我得到一个 500 Internal Server Error
。检查 error.log 我看到:
[Sat Jun 20 04:42:59.502528 2020] [wsgi:error] [pid 6064:tid 140622992238336] [client 118.210.193.245:50042] mod_wsgi (pid=6064): Exception occurred processing WSGI script '/var/www/html/wsgi/dashGAF.wsgi'.
[Sat Jun 20 04:42:59.502675 2020] [wsgi:error] [pid 6064:tid 140622992238336] [client 118.210.193.245:50042] TypeError: 'Dash' object is not callable
如果能帮助解决这个问题,我们将不胜感激!此外,任何有关更改配置文件的建议都会有所帮助。
更多细节:
- 我收到模块导入错误,例如我的 /var/log/apache2/error.log 中的以下内容:
[Sat Jun 20 03:38:58.556219 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] File "/home/ubuntu/dashboards/dashGAF.py", line 2, in <module>
[Sat Jun 20 03:38:58.556265 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] import dash
[Sat Jun 20 03:38:58.556285 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] ImportError: No module named dash
我可以通过 sudo pip install dash==1.13.2
.
修复
我制作了所有的*.py和*.wsgi文件-rwxr-xr-x
我使用 sudo a2ensite dash.conf
启用了站点配置并使用 udo systemctl reload apache2
重新加载了配置。
我相信 python 的版本 运行 是 python2.7(基于 apache error.log);不确定如何指定 2.7 或 3。
如果我将 dashGAF.wsgi 编辑为 from dashGAF import server as application
,我会收到 500 内部错误,但在服务器日志中有以下详细信息:
[Sun Jun 21 06:33:28.181450 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] mod_wsgi (pid=12237): Target WSGI script '/var/www/html/wsgi/dashGAF.wsgi' cannot be loaded as Python module.
[Sun Jun 21 06:33:28.181512 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] mod_wsgi (pid=12237): Exception occurred processing WSGI script '/var/www/html/wsgi/dashGAF.wsgi'.
[Sun Jun 21 06:33:28.181545 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] Traceback (most recent call last):
[Sun Jun 21 06:33:28.181577 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] File "/var/www/html/wsgi/dashGAF.wsgi", line 4, in <module>
[Sun Jun 21 06:33:28.181685 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] from dashGAF import server as application
[Sun Jun 21 06:33:28.181714 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] ImportError: cannot import name server
可能在“目标 WSGI 脚本‘/var/www/html/wsgi/dashGAF.wsgi’无法作为 Python 模块加载”这一点中有一个有用的细节。 ??
- 如果我将 dashGAF.wsgi 编辑为
application = app.server
,我会得到一个 404 Not Foun:
from dashGAF import app
application = app.server
通常,您会在 wsgi 脚本中以 Flask 服务器而不是 Dash 应用程序为目标。也就是说,而不是
from dashGAF import app as application
应该是
from dashGAF import server as application
我对是否应该回答我自己的问题犹豫了一下。 @emher 的回答是问题的一部分 - 但不是整个解决方案。我需要解决一些问题,大部分故障排除都是由 @GrahamDumpleton 在 github 上指导的。如果他愿意,我很高兴他能提供答案。
尽管如此,以下是需要发生的问题和修复:
问题和修复:
- 按照@emher
from dashGAF import server as application
的建议将 Flask 服务器作为目标
- 没有必要包含
routes_pathname_prefix
,它将仪表板解析为 https://ip.address/dashGAF/dashGAF`
/etc/apache2/sites-available/dash.conf
可以显着缩短`(见下文)
_dash-component-suites/dash_renderer/dash_renderer.dev.js
的请求失败,我不得不将 requests_pathname_prefix='/dashGAF/'
选项添加到我的 app = dash.Dash
行 (see link on github)
最终设置:
/etc/apache2/sites-available/dash.conf
WSGIDaemonProcess dashGAF user=ubuntu group=ubuntu home=/home/ubuntu threads=5
WSGIScriptAlias /dashGAF /var/www/html/wsgi/dashGAF.wsgi
WSGIProcessGroup dashGAF
WSGIApplicationGroup %{GLOBAL}
/var/www/html/wsgi/dashGAF.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/home/ubuntu/dashboards/")
from dashGAF import server as application
dashboards/dashGAF.py
同上,但包括:
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, requests_pathname_prefix='/dashGAF/')
server = app.server
我正在尝试将 python dash 应用程序部署到我的 apache 服务器。我遵循了我能找到的有关此配置的少量信息 (officials docs; this troubleshooting thread was a bit better)。当我访问该网站时,页面 returns 变成 500 Internal Server Error
,在服务器错误日志中被描述为 "Dash object not callable"
。这些是配置文件:
>> cat /var/www/html/wsgi/dashGAF.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/home/ubuntu/dashboards/")
from dashGAF import app as application
>> cat /etc/apache2/sites-available/dash.conf
WSGIDaemonProcess dashGAF user=ubuntu group=ubuntu home=/home/ubuntu threads=5
WSGIScriptAlias /dashGAF /var/www/html/wsgi/dashGAF.wsgi
<Directory /home/ubuntu/dashboards>
WSGIProcessGroup dashGAF
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
>> cat dashGAF.py
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, routes_pathname_prefix='/dashGAF/')
server = app.server
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0')
当我在 the_ip_address/dashGAF
访问我的 dash 应用程序时,我得到一个 500 Internal Server Error
。检查 error.log 我看到:
[Sat Jun 20 04:42:59.502528 2020] [wsgi:error] [pid 6064:tid 140622992238336] [client 118.210.193.245:50042] mod_wsgi (pid=6064): Exception occurred processing WSGI script '/var/www/html/wsgi/dashGAF.wsgi'.
[Sat Jun 20 04:42:59.502675 2020] [wsgi:error] [pid 6064:tid 140622992238336] [client 118.210.193.245:50042] TypeError: 'Dash' object is not callable
如果能帮助解决这个问题,我们将不胜感激!此外,任何有关更改配置文件的建议都会有所帮助。
更多细节:
- 我收到模块导入错误,例如我的 /var/log/apache2/error.log 中的以下内容:
[Sat Jun 20 03:38:58.556219 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] File "/home/ubuntu/dashboards/dashGAF.py", line 2, in <module> [Sat Jun 20 03:38:58.556265 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] import dash [Sat Jun 20 03:38:58.556285 2020] [wsgi:error] [pid 583:tid 140297735726848] [client 118.210.193.245:55574] ImportError: No module named dash
我可以通过 sudo pip install dash==1.13.2
.
我制作了所有的*.py和*.wsgi文件
-rwxr-xr-x
我使用
sudo a2ensite dash.conf
启用了站点配置并使用udo systemctl reload apache2
重新加载了配置。我相信 python 的版本 运行 是 python2.7(基于 apache error.log);不确定如何指定 2.7 或 3。
如果我将 dashGAF.wsgi 编辑为
from dashGAF import server as application
,我会收到 500 内部错误,但在服务器日志中有以下详细信息:
[Sun Jun 21 06:33:28.181450 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] mod_wsgi (pid=12237): Target WSGI script '/var/www/html/wsgi/dashGAF.wsgi' cannot be loaded as Python module.
[Sun Jun 21 06:33:28.181512 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] mod_wsgi (pid=12237): Exception occurred processing WSGI script '/var/www/html/wsgi/dashGAF.wsgi'.
[Sun Jun 21 06:33:28.181545 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] Traceback (most recent call last):
[Sun Jun 21 06:33:28.181577 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] File "/var/www/html/wsgi/dashGAF.wsgi", line 4, in <module>
[Sun Jun 21 06:33:28.181685 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] from dashGAF import server as application
[Sun Jun 21 06:33:28.181714 2020] [wsgi:error] [pid 12237:tid 139670549669632] [client 118.210.193.245:52221] ImportError: cannot import name server
可能在“目标 WSGI 脚本‘/var/www/html/wsgi/dashGAF.wsgi’无法作为 Python 模块加载”这一点中有一个有用的细节。 ??
- 如果我将 dashGAF.wsgi 编辑为
application = app.server
,我会得到一个 404 Not Foun:
from dashGAF import app
application = app.server
通常,您会在 wsgi 脚本中以 Flask 服务器而不是 Dash 应用程序为目标。也就是说,而不是
from dashGAF import app as application
应该是
from dashGAF import server as application
我对是否应该回答我自己的问题犹豫了一下。 @emher 的回答是问题的一部分 - 但不是整个解决方案。我需要解决一些问题,大部分故障排除都是由 @GrahamDumpleton 在 github 上指导的。如果他愿意,我很高兴他能提供答案。
尽管如此,以下是需要发生的问题和修复:
问题和修复:
- 按照@emher
from dashGAF import server as application
的建议将 Flask 服务器作为目标
- 没有必要包含
routes_pathname_prefix
,它将仪表板解析为 https://ip.address/dashGAF/dashGAF` /etc/apache2/sites-available/dash.conf
可以显着缩短`(见下文)_dash-component-suites/dash_renderer/dash_renderer.dev.js
的请求失败,我不得不将requests_pathname_prefix='/dashGAF/'
选项添加到我的app = dash.Dash
行 (see link on github)
最终设置:
/etc/apache2/sites-available/dash.conf
WSGIDaemonProcess dashGAF user=ubuntu group=ubuntu home=/home/ubuntu threads=5
WSGIScriptAlias /dashGAF /var/www/html/wsgi/dashGAF.wsgi
WSGIProcessGroup dashGAF
WSGIApplicationGroup %{GLOBAL}
/var/www/html/wsgi/dashGAF.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/home/ubuntu/dashboards/")
from dashGAF import server as application
dashboards/dashGAF.py 同上,但包括:
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, requests_pathname_prefix='/dashGAF/')
server = app.server