Skip to content Skip to sidebar Skip to footer

Error 500 While Running A Python Flask Application On IIS. How To Get The Actual Error

I try to get a Flask application running on an IIS on windows. The reason is to get single-sign-on with windows authentication done using the IIS mechanisms. I got it running on my

Solution 1:

To configure python flask app in iis you could follow the below steps:

  • First, you need to install the python,wfastcgi, and flask at your server.
  • You can download the python from below link:

https://www.python.org/downloads/

note: if possible please use python version above 3.6.

after installing python install the wfastcgi.run the command prompt as administrator and run below command:

pip install wfastcgi

wfastcgi-enable

below is my flask example:

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
    app.run()

after creating an application to run it use below command:

python app.py

now enable the cgi feature of iis:

enter image description here

  • now open iis.
  • right-click on the server name and select add site.

enter image description here

  • enter the site name physical path and the site binding.
  • after adding site select the site name and select the handler mapping feature from the middle pane.

enter image description here

  • Click “Add Module Mapping”

enter image description here

executable path value:

C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py

enter image description here

  • Click “Request Restrictions”. Make sure “Invoke handler only if the request is mapped to:” checkbox is unchecked:

enter image description here

  • Click “Yes” here:

enter image description here

  • now go back and select the application setting feature.

enter image description here

  • click add from the action pane.

enter image description here

  • Set the PYTHONPATH variable(which is your site folder path):

enter image description here

  • And the WSGI_HANDLER (my Flask app is named app.py so the value is app.app — if yours is named site.py it would be site.app or similar):

enter image description here

  • Click OK and browse to your site.

enter image description here


Solution 2:

All IIS sites have a web.config file in the root which holds all the settings. You can edit this manually with a text editor (it's just XML) or you can use the IIS GUI.

It sounds to me like the default <customErrors> setting is On or RemoteOnly which means it shows actual errors on your local dev machine, but hides them with "friendly" (but unhelpful) error pages on production when you view the site remotely.

Look in your web.config for <customErrors> inside the system.web element (see below). Set it to mode="Off", this should hopefully mean you can see the actual error message.

<configuration>
    <system.web>
        <customErrors mode="Off">
        </customErrors>
    </system.web>
</configuration>

Solution 3:

I got the same error and have solved it by add access rights to the folder of python. In your case, the python folder path is c:\program files\python37, so try to add IIS_IUSRS with read and execution access rights.

enter image description here

The other option is that changing AppPool identity of the web application to LocalSystem as IIS manager.

enter image description here


Solution 4:

If your file permissions are correct, the problem might lie in your Application Pools settings.

  1. Go to IIS manager
  2. Click on your server's Application Pools tab
  3. Click Set Application Pool Defaults...
  4. Set the Identity under Process Model to LocalSystem

Post a Comment for "Error 500 While Running A Python Flask Application On IIS. How To Get The Actual Error"