本文介绍了部署在apache服务器上的Dash失败,并显示"Dash对象不可调用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将python dash应用程序部署到我的apache服务器.我遵循了一些关于此配置的少量信息(官方文档; 此故障排除线程要好一些).当我访问该网站时,页面返回 500 Internal Server Error ,该错误在服务器错误日志中描述为无法调用Dash对象" .这些是配置文件:

I'm trying to deploy a python dash app to my apache server. I followed the scant amount of information about this configuration that I could find (officials docs; this troubleshooting thread was a bit better). When I visit the website, the page returns a 500 Internal Server Error, which is described as "Dash object not callable" in the server error log. These are the config files:

>> 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我看到:

When I visit my dash app at the_ip_address/dashGAF, I get a 500 Internal Server Error. Inspecting the error.log I see:

[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

在解决此问题方面的任何帮助将不胜感激!此外,任何有关更改配置文件的建议都将有所帮助.

Any help in fixing this issue would be GREATLY appreciated! Also any suggestions for changes to the configuration files would be helpful.

更多详细信息:

  • 我在/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 来进行修复.

Which I was able to fix by doing a sudo pip install dash==1.13.2.

  • 我已经制作了所有* .py和* .wsgi文件 -rwxr-xr-x

我使用 sudo a2ensite dash.conf 启用了站点配置,并使用 udo systemctl reload apache2 重新加载了配置.

I enabled the site config with sudo a2ensite dash.conf and reloaded config with udo systemctl reload apache2.

我相信正在运行的python版本是python2.7(基于apache error.log);不确定确切如何指定2.7或3.

I believe the version of python being run is python2.7 (based on the apache error.log); Not sure exactly how to specify 2.7 or 3.

如果我编辑dashGAF.wsgi以将dashGAF导入服务器中的作为应用程序,则会收到500 Internal错误,但服务器日志中包含以下详细信息:

If I edit the dashGAF.wsgi to have from dashGAF import server as application I get a 500 Internal error, but with the following details in the server log:

[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:
  • If I edit the dashGAF.wsgi to have application = app.server I get a 404 Not Foun:
from dashGAF import app
application = app.server

推荐答案

对于我是否应该回答自己的问题,我有些犹豫.@emher的回答是问题的一部分-但不是整个解决方案.我需要解决一些问题,而大部分故障排除由@GrahamDumpleton在 github 上进行的指导一个>.如果他愿意,我很高兴他提供答案.

I've hesitated a little bit on whether I should answer my own question. @emher 's answer was part of the problem - but not the whole solution. I needed to fix a few problems, and much of that troubleshooting was guided by @GrahamDumpleton on github. I'm more than happy for him to provide the answer if he wants.

不过,这是需要发生的问题和修复程序:

Nevertheless, here are the problems and fixes that needed to occur:

问题和解决方法:

  • Target the Flask server as @emher suggested with from dashGAF import server as application
  • it is not necessary to include a routes_pathname_prefix, which was resolving the dashboard to https://ip.address/dashGAF/dashGAF`
  • the /etc/apache2/sites-available/dash.conf could be significantly shortened` (see below)
  • There was a failed request for _dash-component-suites/dash_renderer/dash_renderer.dev.js, and I had to add requests_pathname_prefix='/dashGAF/' option to my app = dash.Dash line (see link on github)

最终设置:

/etc/apache2/sites-available/dash.conf

/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

/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如上所述,但包括:

dashboards/dashGAF.pyAs above, but include:

app = dash.Dash(__name__, external_stylesheets=external_stylesheets, requests_pathname_prefix='/dashGAF/')
server = app.server

这篇关于部署在apache服务器上的Dash失败,并显示"Dash对象不可调用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 23:58