托管Flask(Python)应用会引发CGI错误 [英] Hosting Flask(Python) app throws CGI error

查看:113
本文介绍了托管Flask(Python)应用会引发CGI错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照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.

  1. 我在D:\home下安装了Python扩展python364x86.也许您安装的是python364x64.
  2. 我通过Kudo控制台在路径D:\home\python364x86中命令了pip install flask.
  3. 我在wwwroot下的文件结构如下图所示,通过命令tree /F /A.
  4. __init__.py文件的内容类似于Flask官方Hello演示.

  1. I installed a Python extension python364x86 under D:\home. Maybe yours installed is python364x64.
  2. I commanded pip install flask in the path D:\home\python364x86 via Kudo console.
  3. My file structure under wwwroot as the figure below via command tree /F /A.
  4. The __init__.py file content is like the Flask offical Hello 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆