Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

azure - Hosting Flask(Python) app throws CGI error

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/

enter image description here

Any idea how to fix this error pls

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. enter image description here
  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. enter image description here

If your case is different from mine, please post your web.config file content and other necessary info to help fixing up your issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...