Dash 应用程序拒绝启动:“127.0.0.1 拒绝连接。”

dash app refusing to start: '127.0.0.1 refused to connect.'

我正在尝试 运行 示例 dash 应用程序,但在尝试 运行 时,浏览器说它拒绝连接。我检查过 Google Chrome 可以通过防火墙访问。

示例代码为:

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)

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)

这是我浏览器的图片:

有人看懂了吗?

改变

app.run_server(debug=True)

app.run_server(debug=False)

然后试试。

首先检查你访问的端口是否正确,默认的(通常)是8050:http://localhost:8050/

另外,检查是否有其他Dash码运行,可能占用端口

如果它不起作用,请尝试将主机确定为 app.runserver(args) 中的参数,如下所示:

app.run_server(host='0.0.0.0', debug=True)

您可能还想将端口确定为这样的参数:

app.run_server(host='0.0.0.0', port=8050, debug=True)

我运行遇到了类似的问题。我在远程服务器上的容器中 运行 Jupyter Lab。我无法提供具体代码,因为我不知道您的配置,但对我而言,这涉及从 127.0.0.1:8050 转发到容器上的端口 8050。

希望这对以后的人有所帮助。

遇到同样的问题,设置“debug=False”绝对不是解决方案,因为“debug=True”是教程的一部分,用于显示“热重载”功能(参见 https://dash.plotly.com/layout ).

稍微看了一下,从下面的网站上我注意到“alitarraf”提到 python 可能会卡在旧版本上: https://github.com/plotly/dash/issues/108

看到后,我在任务管理器的详细信息选项卡中关闭了“python.exe”。 这为我解决了问题。

编辑: 重新启动后,问题似乎也消失了。

我做了这个改变:

if __name__ == '__main__':
    app.run_server(host='localhost',port=8005)

代码对我来说工作得很好!

我遇到了同样的问题,发现我忘记启动应用程序 运行 python app.py 在访问我的浏览器之前。 (假设您的文件名为 app.py)。一旦我这样做了,一切都很好。

https://dash.plotly.com/layout 展示了如何做到这一点