首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flask、Windows、IIS、Plotly-Dash。读取WSGI处理程序时出错

Flask、Windows、IIS、Plotly-Dash。读取WSGI处理程序时出错
EN

Stack Overflow用户
提问于 2018-04-13 18:02:22
回答 2查看 2.5K关注 0票数 2

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

除了我的网站在wwwroot文件夹中的位置之外,我已经使用以下指南逐字地设置了Flask:Flask on IIS

当我使用最基本的应用程序时,它工作得很好,例如下面的代码:

代码语言:javascript
复制
from flask import Flask
app = Flask(__name__)

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

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

但是如果我尝试一些稍微复杂一些的东西,比如basic Dash演示:

代码语言:javascript
复制
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)

我得到一个错误,如下所示(为了便于解释,我已经尝试对其进行了整理):

代码语言:javascript
复制
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,现在得到以下错误:

代码语言:javascript
复制
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 
EN

回答 2

Stack Overflow用户

发布于 2018-04-14 04:19:33

尝试使用wfastcgi.pyMicrosoft's blessed version及其附带的配置说明。旧版本的wfastcgi.py在尝试将二进制输出写入非二进制对象时存在问题,这与您在这里看到的情况类似。

直到最近,在线提供的使用IIS配置Flask的说明都有点令人困惑。除非你使用Azure,否则微软自己的解决方案是最容易配置的。

票数 0
EN

Stack Overflow用户

发布于 2019-08-03 09:27:21

我也遇到过类似的问题。以下是我为使其工作而运行的步骤:

1)确保"Add Module Mapping“可执行文件中的python.exe、pipe和wfastcgi.py文件之间没有空格。有关说明,请参阅此link。这为我抛出了一个500错误。

2)确保您使用的是flask应用实例,而不是dash应用实例。请参见Dash Deployment User Guide这是通过在WSGI_HANDLER环境变量中使用app.server而不是app.app来实现的。来自% 1的链接中的屏幕快照。

3)最后,如果您从原始问题中得到错误,请按照注释中的指示卸载IPython。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49814358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档