twi*_*wip 1 python iis flask wfastcgi
我正在尝试在Windows Server 2012的IIS上部署Flask服务。要达到这一点:
从localhost运行会返回我期望的输出。但是,当我从站点名称访问该网站时,返回以下错误(路径省略):
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "wfastcgi.py", line 586, in get_wsgi_handler
raise Exception('WSGI_HANDLER env var must be set')
Exception: WSGI_HANDLER env var must be set
Run Code Online (Sandbox Code Playgroud)
无论是在服务器上还是在域中的另一台计算机上,都是这种情况。似乎当从本地主机以外的其他任何地方请求该应用程序时,环境无法访问。什么都不会写入wfastcgi日志。
我已经包含app.py和Web.config下方。我在scriptProcessor这里省略了路径,但是将其设置为wfastcgi-enable返回的值。
从本地主机运行时,环境可用。在locahost之外调用时,如何使环境对应用程序可用?
app.py
from flask import Flask
myapp = Flask(__name__)
@myapp.route("/hello")
def hello():
return "Hello from flask!"
if __name__ == "__main__":
myapp.run(port=8080)
Run Code Online (Sandbox Code Playgroud)
Web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="app.myapp" />
<add key="PYTHONPATH" value="c:/inetpub/wwwroot/flask-services/" />
<add key="WSGI_LOG" value="C:/TMP/logs/app.log" />
</appSettings>
<system.webServer>
<handlers>
<add name="python-wfastcgi" path="*" verb="*" modules="FastCgiModule" scriptProcessor="[Omitted]" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
最近,我们在IIS 7,Flask 0.12和Python 3.6.4中遇到了类似的问题。你web.config看起来不错。两个建议:
virtualenv用于您的脚本处理器。它避免了使用系统级Python安装带来的副作用。这样调试起来更容易。| 归档时间: |
|
| 查看次数: |
4794 次 |
| 最近记录: |