【问题标题】:Flask, Windows, IIS, Plotly-Dash. Error Occured While reading WSGI handler烧瓶,Windows,IIS,Plotly-Dash。读取 WSGI 处理程序时发生错误
【发布时间】:2018-04-13 10:02:21
【问题描述】:

我希望你能帮助我解决我在尝试在 Windows 服务器上部署 plotly-dash 时遇到的错误。

我已经按照以下指南逐字逐句设置了 Flask,但我的网站在 wwwroot 文件夹中的位置除外: Flask on IIS

当我使用最基本的应用程序时,它运行良好,例如以下代码:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello from FastCGI via IIS!"

if __name__ == "__main__":
    app.run()

但是,如果我尝试一些更复杂的东西,比如基本的 Dash 演示:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

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)

我收到如下错误(我已尝试整理以方便解释):

Error occurred while reading WSGI handler: 
Traceback (most recent call last): 
    File "C:\inetpub\wwwroot\wfastcgi.py", line 791, in main env, handler = read_wsgi_handler(response.physical_path) 
    File "C:\inetpub\wwwroot\wfastcgi.py", line 633, in read_wsgi_handler handler = get_wsgi_handler(os.getenv("WSGI_HANDLER")) 
    File "C:\inetpub\wwwroot\wfastcgi.py", line 600, in get_wsgi_handler handler = __import__(module_name, fromlist=[name_list[0][0]]) 
    File ".\app.py", line 1, in import dash 
    File "C:\Python36\lib\site-packages\dash\__init__.py", line 1, in from .dash import Dash # noqa: F401 
    File "C:\Python36\lib\site-packages\dash\dash.py", line 12, in import plotly 
    File "C:\Python36\lib\site-packages\plotly\__init__.py", line 31, in from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools, 
    File "C:\Python36\lib\site-packages\plotly\plotly\__init__.py", line 10, in from . plotly import ( 
    File "C:\Python36\lib\site-packages\plotly\plotly\plotly.py", line 30, in from plotly import exceptions, files, session, tools, utils 
    File "C:\Python36\lib\site-packages\plotly\tools.py", line 59, in ipython_core_display = optional_imports.get_module('IPython.core.display') 
    File "C:\Python36\lib\site-packages\plotly\optional_imports.py", line 23, in get_module return import_module(name) 
    File "C:\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) 
    File "C:\Python36\lib\site-packages\IPython\__init__.py", line 55, in from .terminal.embed import embed 
    File "C:\Python36\lib\site-packages\IPython\terminal\embed.py", line 15, in from IPython.core.interactiveshell import DummyMod, InteractiveShell 
    File "C:\Python36\lib\site-packages\IPython\core\interactiveshell.py", line 61, in from IPython.utils import io 
    File "C:\Python36\lib\site-packages\IPython\utils\io.py", line 95, in stdin = IOStream(sys.stdin, fallback=devnull) 
    File "C:\Python36\lib\site-packages\IPython\utils\io.py", line 39, in __init__ for meth in filter(clone, dir(stream)): 
    File "C:\Python36\lib\site-packages\IPython\utils\io.py", line 38, in clone return not hasattr(self, meth) and not meth.startswith('_') 
    File "C:\Python36\lib\site-packages\IPython\utils\io.py", line 82, in closed return self.stream.closed 
    ValueError: underlying buffer has been detached StdOut: StdErr:

我已经进行了大量的谷歌搜索并尽我所能来解码这个错误,但我遇到了障碍。有人有什么想法吗?

根据@susodapop 的建议,我删除了 IPython,现在出现以下错误:

Error occurred: Traceback (most recent call last): File "C:\inetpub\wwwroot\wfastcgi.py", line 847, in main result = handler(record.params, response.start) 
TypeError: 'Dash' object is not callable StdOut: StdErr: C:\Python34\lib\site-packages\plotly\tools.py:103: UserWarning: Looks like you don't have 'read-write' permission to your 'home' ('~') directory or to our '~/.plotly' directory. 
That means plotly's python api can't setup local configuration files. No problem though! You'll just have to sign-in using 'plotly.plotly.sign_in()'. For help with that: 'help(plotly.plotly.sign_in)'. Questions? Visit https://support.plot.ly 

【问题讨论】:

    标签: python iis flask plotly plotly-dash


    【解决方案1】:

    尝试使用Microsoft's blessed versionwfastcgi.py 及其随附的配置说明。 wfastcgi.py 的旧版本在尝试将二进制输出写入非二进制对象时遇到问题,这与您在此处看到的类似。

    直到最近,网上提供的使用 IIS 配置 Flask 的说明都有些混乱。除非您使用的是 Azure,否则 Microsoft 自己的解决方案是最容易配置的。

    【讨论】:

    • 试过了,但没有成功。仍然得到同样的错误
    • 看起来根本问题是 plotly 中的“optional_imports”模块。此处代码:github.com/plotly/plotly.py/blob/master/plotly/…。为了进一步调试,我会添加一个“except ValueError: continue”语句,看看会发生什么。您的 IPython 安装可能存在潜在问题。
    • 好的,谢谢 - 值得我重新安装 python 吗?由于防火墙限制,我不得不从另一个 python 安装中复制库而不是通过 pip 安装,这可能是根本原因吗?
    • 您可能不需要重新安装 Python 本身。只是 IronPython 扩展,因为它是引发错误的包。如果你不能使用 pip,你可以从 pythonhosted 下载包,将它保存到你的站点包目录,然后手动运行它的 setup.py。
    • 行得通!我刚刚卸载了 IPython——不过我遇到了一个新错误。这仅与Windows文件夹权限有关吗?我会把它放在主帖中
    【解决方案2】:

    我遇到了类似的问题。以下是我运行的步骤:

    1) 确保“添加模块映射”可执行文件中的 python.exe、管道和 wfastcgi.py 文件之间没有空格。请参阅此link 以获得解释。这给我带来了 500 错误。

    2) 确保您使用的是烧瓶应用实例而不是破折号应用实例。请参阅Dash Deployment User Guide 这是通过在 WSGI_HANDLER 环境变量中使用 app.server 而不是 app.app 来完成的。来自 1 的链接中的屏幕截图。

    3) 最后,如果您收到原始问题的错误,请按照 cmets 中的说明卸载 IPython。

    在这三个问题之后。我让我的 dash 应用程序部署在 IIS 上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      相关资源
      最近更新 更多