托管 Flask(Python) 应用程序引发 CGI 错误 [英] Hosting Flask(Python) app throws CGI error
问题描述
我已按照 azure 网站执行了所有步骤.我可以看到在 Azure 上运行的 python 3.6 版本.我已经安装了 python 3.6 扩展并添加了一个适当的 web.config 文件.当我尝试打开我的 URL 时,出现以下错误
知道如何解决这个错误请
通常,该问题是由您的 web.config
文件配置不正确导致的,无法从 IIS 启动您的 Flask 应用程序.
>
这里是我在Azure网站上部署flask Hello World
应用的案例,你可以参考它来检查你的部署是否正确.
- 我在
D:home
下安装了 Python 扩展python364x86
.也许你安装的是python364x64
. - 我通过 Kudo 控制台在路径
D:homepython364x86
中命令pip install flask
. - 我在
wwwroot
下的文件结构如下图通过命令tree/F/A
. __init__.py
文件内容类似于 Flask 官方Hello
演示.from flask import Flaskapp = Flask(__name__)@app.route("/")定义你好():返回世界你好!"如果 __name__ == "__main__":应用程序运行()
我的
web.config
文件内容如下,注意python364x86
我在标签的属性
.scriptProcessor
中使用了system.webServer >处理 >在此处添加</处理程序></system.webServer></配置>
然后演示应用程序工作.
如果您的情况与我的不同,请发布您的 web.config
文件内容和其他必要信息,以帮助解决您的问题.
I have followed all the steps as per the azure website. I can see the python 3.6 version running on Azure. I have installed the python 3.6 extension and added a proper web.config file. When I try to open my URL I am getting the below error
http://myuniqueappname114.azurewebsites.net/
Any idea how to fix this error pls
Generally, the issue was caused by your web.config
file configured incorrectly to not start up your flask app from IIS.
Here is my case for deploying flask Hello World
app on Azure Website, which you can refer to to check your deployment whether be correct.
- I installed a Python extension
python364x86
underD:home
. Maybe yours installed ispython364x64
. - I commanded
pip install flask
in the pathD:homepython364x86
via Kudo console. - My file structure under
wwwroot
as the figure below via commandtree /F /A
. The
__init__.py
file content is like the Flask officalHello
demo.from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run()
My
web.config
file content is as below, notepython364x86
I used in the propertyscriptProcessor
of tagsystem.webServer > handles > add
at here.<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="PYTHONPATH" value="D:homesitewwwroot" /> <add key="WSGI_HANDLER" value="myflask.app" /> </appSettings> <system.webServer> <handlers> <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:homepython364x86python.exe|D:homepython364x86wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/> </handlers> </system.webServer> </configuration>
Then the demo app works.
If your case is different from mine, please post your web.config
file content and other necessary info to help fixing up your issue.
这篇关于托管 Flask(Python) 应用程序引发 CGI 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!