托管Flask(Python)应用会引发CGI错误 [英] Hosting Flask(Python) app throws CGI error
问题描述
我已经按照azure网站执行了所有步骤.我可以看到在Azure上运行的python 3.6版本.我已经安装了python 3.6扩展名并添加了正确的web.config文件.当我尝试打开我的URL时,出现以下错误
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
推荐答案
通常,此问题是由于您的web.config
文件配置不正确而导致无法从IIS启动Flask应用程序引起的.
Generally, the issue was caused by your web.config
file configured incorrectly to not start up your flask app from IIS.
这是我在Azure网站上部署flask Hello World
应用程序的情况,您可以参考该应用程序检查您的部署是否正确.
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.
- 我在
D:\home
下安装了Python扩展python364x86
.也许您安装的是python364x64
. - 我通过Kudo控制台在路径
D:\home\python364x86
中命令了pip install flask
. - 我在
wwwroot
下的文件结构如下图所示,通过命令tree /F /A
. -
__init__.py
文件的内容类似于Flask官方Hello
演示.
- I installed a Python extension
python364x86
underD:\home
. Maybe yours installed ispython364x64
. - I commanded
pip install flask
in the pathD:\home\python364x86
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()
我的web.config
文件内容如下,请注意python364x86
我在这里在标签system.webServer > handles > add
的属性scriptProcessor
中使用了.
My web.config
file content is as below, note python364x86
I used in the property scriptProcessor
of tag system.webServer > handles > add
at here.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<add key="WSGI_HANDLER" value="myflask.app" />
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x86\python.exe|D:\home\python364x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
</system.webServer>
</configuration>
然后演示应用程序开始工作.
Then the demo app works.
如果您的案件与我的案件不同,请发布您的web.config
文件内容和其他必要信息,以帮助解决您的问题.
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屋!