注意: Dash是一个python软件包,用于通过plotly(网站here)构建仪表板。 Flask是一个Python软件包,用于构建python Web框架(网站here和AWS教程here)。我正在使用python 3.6,所有软件包版本都可以在下方requirements.txt中看到
问题:将Dash应用启动到我的AWS EB时出现错误。
当我在127.0.0.1:8050上本地运行时,我的破折号起作用了。但是,当我$ eb deploy时,我在我的AWS EB URL上得到了这个:

我的文件结构是这样的(其中eb-flask是我的flask目录):

~/AWS/servers/flask-s
  |-- eb-virt                   }
  |    |-- bin                  }
  |    |-- include              } virtualenv files etc
  |    |-- lib                  }
  |    `-- pip-selfcheck.json   }
  |
  |-- eb-flask              <--- where I ran eb init
  |    |-- application.py
  |    |-- requirements.txt
  |    |-- .gitignore
  |    |-- .elasticbeanstalk
  `         `-- config.yml
使用$ eb config时:
aws:elasticbeanstalk:container:python:
  NumProcesses: '1'
  NumThreads: '15'
  StaticFiles: /static/=static/
  WSGIPath: application.py
我的application.py代码已从https://dash.plot.ly/deployment提升为测试。
import flask
import os
import dash
import dash_core_components as dcc
import dash_html_components as html

#app = dash.Dash(_name_)
#server = app.server

server = flask.Flask(_name_)
application = dash.Dash(_name_, server=server)

application.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})

application.layout = html.Div([
    html.H2('Hello World'),
    dcc.Dropdown(
        id='dropdown',
        options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
        value='LA'
    ),
    html.Div(id='display-value')
])

@application.callback(dash.dependencies.Output('display-value', 'children'),
              [dash.dependencies.Input('dropdown', 'value')])
def display_value(value):
return 'You have selected "{}"'.format(value)

if _name_ == '_main_':
    application.run_server(debug=True)
#app.run_server()
requirements.txt显然是点子卡住。在这一点上,这只是长颈瓶,破折号和绘图所必需的软件包:
certifi==2018.4.16
chardet==3.0.4
click==6.7
dash==0.21.1
dash-core-components==0.22.1
dash-html-components==0.10.1
dash-renderer==0.12.1
decorator==4.3.0
Flask==1.0.2
Flask-Compress==1.4.0
gunicorn==19.8.1
idna==2.6
ipython-genutils==0.2.0
itsdangerous==0.24
Jinja2==2.10
jsonschema==2.6.0
jupyter-core==4.4.0
MarkupSafe==1.0
nbformat==4.4.0
numpy==1.14.3
pandas==0.23.0
plotly==2.6.0
python-dateutil==2.7.3
pytz==2018.4
requests==2.18.4
six==1.11.0
traitlets==4.3.2
urllib3==1.22
Werkzeug==0.14.1
很明显,服务器端出了问题。当我运行(eb-virt) $ python application.py时,我可以在本地访问该站点。我从HTTP GET获得以下响应:
(eb-virt): eb-flask $ python application.py
 * Serving Flask app "application" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 190-847-760
127.0.0.1 - - [22/May/2018 18:41:30] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [22/May/2018 18:41:31] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [22/May/2018 18:41:31] "GET /_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [22/May/2018 18:41:31] "POST /_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [22/May/2018 18:41:31] "GET /favicon.ico HTTP/1.1" 200 -
但是,当我$ eb deploy时,出现上述内部服务器错误。感谢您的帮助。
当我enable logging时,我在本地获取application.logger.addHandler(handler) AttributeError: 'Dash' object has no attribute 'logger'。部署时,日志文件没有附加错误,只是空白。

最佳答案

我认为问题在于application.run_server(debug=True)方法将localhost作为默认主机。这意味着该应用程序已部署到127.0.0.1,并且您只能从运行该应用程序的计算机内部对其进行访问。这就解释了为什么您只能在本地访问该应用程序(无论是从您的计算机还是在实例内部)。在部署到Elastic Beanstalk时,您需要将主机指定为0.0.0.0-所有IP地址(不建议在生产环境中部署debug=True!):

if __name__ == '__main__':
    app.run_server(host="0.0.0.0")

检查this GitHub示例Flask应用程序Beanstalk部署。

关于python - 内部服务器错误: Dash on Flask on AWS Elastic Beanstalk,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50474000/

10-11 09:28