使用烧瓶和 wfastcgi 在 iis 上绘制破折号
plotly-dash on iis with flask and wfastcgi
我已经用 python 和 wfastcgi.py 配置了 IIS,主要是让它工作。当尝试简单的东西时,它 returns 预期的内容。
我现在的问题是使用属性路由让 flask 和 plotly/dash 在 IIS 下工作。
我的web.config如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python36\python.exe|C:\Python36\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="index.wsgi_app" />
<add key="PYTHONPATH" value="C:/inetpub/wwwroot/python/venv/Scripts/python36.zip;C:/inetpub/wwwroot/python/venv/DLLs;C:/inetpub/wwwroot/python/venv/lib;C:/inetpub/wwwroot/python/venv/Scripts;c:/python36/Lib', 'c:/python36/DLLs;C:/inetpub/wwwroot/python/venv;C:/inetpub/wwwroot/python/venv/lib/site-packages" />
<!-- Optional settings -->
<add key="WSGI_LOG" value="C:\temp\my_app.log" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
<add key="APPINSIGHTS_INSTRUMENTATIONKEY" value="__instrumentation_key__" />
<add key="WSGI_PTVSD_SECRET" value="__secret_code__" />
<add key="WSGI_PTVSD_ADDRESS" value="ipaddress:port" />
</appSettings>
</configuration>
我创建了一个 index.py 文件,当我使用
from flask import Flask
from SimpleDash1 import app as sd1
from WebAppExampleA import app as waea
app = Flask(__name__)
@app.route("/")
def hello():
response = ["Hello, world!\n"]
return (line.encode("utf-8") for line in response)
def wsgi_app(environ,start_response):
start_response('200 OK', [('Content-type', 'text/html'), ('Content-encoding', 'utf-8')])
return hello()
if __name__ == "__main__":
app.run()
它工作正常,但不能完全满足我的 plotly 应用程序的需求。
为了尝试加载我的 plotly 应用程序,我使用了这个:
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from app import app
from apps import web_example_a
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/apps/web_example_a':
return web_example_a.layout
#elif pathname == '/apps/app2':
# return app2.layout
else:
return '404'
if __name__ == '__main__':
app.run_server(debug=True)
但现在我不知道我需要在 web.config 中配置什么入口点作为我的 WSGI_HANDLER。
如果我尝试将 WSGI_HANDLER 更改为 "index.display_page",我会收到一条错误消息:
Error occurred:
Traceback (most recent call last): File
"C:\Python36\Scripts\wfastcgi.py", line 849, in main
for part in result: File "C:\python36\lib\site-packages\applicationinsights\requests\WSGIApplication.py",
line 70, in call
for part in self._wsgi_application(environ, status_interceptor): File "C:\python36\lib\site-packages\dash\dash.py", line 498, in
add_context
output_value = func(*args, **kwargs) TypeError: display_page() takes 1 positional argument but 2 were given
StdOut:
StdErr: C:\python36\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
Dash 应用程序的 WSGI 入口点是附加到 Dash 实例的 Flask 实例。这意味着您想将 WSGI 处理程序指向 app.server
(其中 app
是 Dash 实例)。
WSGI 服务器在将模块作为入口点传递时通常会查找属性 application
。因此,通常要做的事情是创建一个入口点文件 wsgi.py
,在您的情况下,它只需包含以下内容:
from index import app
application = app.server
我已经用 python 和 wfastcgi.py 配置了 IIS,主要是让它工作。当尝试简单的东西时,它 returns 预期的内容。
我现在的问题是使用属性路由让 flask 和 plotly/dash 在 IIS 下工作。
我的web.config如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python36\python.exe|C:\Python36\Scripts\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="index.wsgi_app" />
<add key="PYTHONPATH" value="C:/inetpub/wwwroot/python/venv/Scripts/python36.zip;C:/inetpub/wwwroot/python/venv/DLLs;C:/inetpub/wwwroot/python/venv/lib;C:/inetpub/wwwroot/python/venv/Scripts;c:/python36/Lib', 'c:/python36/DLLs;C:/inetpub/wwwroot/python/venv;C:/inetpub/wwwroot/python/venv/lib/site-packages" />
<!-- Optional settings -->
<add key="WSGI_LOG" value="C:\temp\my_app.log" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
<add key="APPINSIGHTS_INSTRUMENTATIONKEY" value="__instrumentation_key__" />
<add key="WSGI_PTVSD_SECRET" value="__secret_code__" />
<add key="WSGI_PTVSD_ADDRESS" value="ipaddress:port" />
</appSettings>
</configuration>
我创建了一个 index.py 文件,当我使用
from flask import Flask
from SimpleDash1 import app as sd1
from WebAppExampleA import app as waea
app = Flask(__name__)
@app.route("/")
def hello():
response = ["Hello, world!\n"]
return (line.encode("utf-8") for line in response)
def wsgi_app(environ,start_response):
start_response('200 OK', [('Content-type', 'text/html'), ('Content-encoding', 'utf-8')])
return hello()
if __name__ == "__main__":
app.run()
它工作正常,但不能完全满足我的 plotly 应用程序的需求。 为了尝试加载我的 plotly 应用程序,我使用了这个:
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from app import app
from apps import web_example_a
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/apps/web_example_a':
return web_example_a.layout
#elif pathname == '/apps/app2':
# return app2.layout
else:
return '404'
if __name__ == '__main__':
app.run_server(debug=True)
但现在我不知道我需要在 web.config 中配置什么入口点作为我的 WSGI_HANDLER。 如果我尝试将 WSGI_HANDLER 更改为 "index.display_page",我会收到一条错误消息:
Error occurred:
Traceback (most recent call last): File "C:\Python36\Scripts\wfastcgi.py", line 849, in main for part in result: File "C:\python36\lib\site-packages\applicationinsights\requests\WSGIApplication.py", line 70, in call for part in self._wsgi_application(environ, status_interceptor): File "C:\python36\lib\site-packages\dash\dash.py", line 498, in add_context output_value = func(*args, **kwargs) TypeError: display_page() takes 1 positional argument but 2 were given
StdOut:
StdErr: C:\python36\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
Dash 应用程序的 WSGI 入口点是附加到 Dash 实例的 Flask 实例。这意味着您想将 WSGI 处理程序指向 app.server
(其中 app
是 Dash 实例)。
WSGI 服务器在将模块作为入口点传递时通常会查找属性 application
。因此,通常要做的事情是创建一个入口点文件 wsgi.py
,在您的情况下,它只需包含以下内容:
from index import app
application = app.server