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

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

问题描述

我已按照 azure 网站执行了所有步骤.我可以看到在 Azure 上运行的 python 3.6 版本.我已经安装了 python 3.6 扩展并添加了一个适当的 web.config 文件.当我尝试打开我的 URL 时,出现以下错误

知道如何解决这个错误请

解决方案

通常,该问题是由您的 web.config 文件配置不正确导致的,无法从 IIS 启动您的 Flask 应用程序.

>

这里是我在Azure网站上部署flask Hello World应用的案例,你可以参考它来检查你的部署是否正确.

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

    from flask import Flaskapp = Flask(__name__)@app.route("/")定义你好():返回世界你好!"如果 __name__ == "__main__":应用程序运行()

  5. 我的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.

  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:homepython364x86 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()
    

  5. 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: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屋!

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