Error 500 While Running A Python Flask Application On IIS. How To Get The Actual Error
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:
- now open iis.
- right-click on the server name and select add site.
- 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.
- Click “Add Module Mapping”
executable path value:
C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py
- Click “Request Restrictions”. Make sure “Invoke handler only if the request is mapped to:” checkbox is unchecked:
- Click “Yes” here:
- now go back and select the application setting feature.
- click add from the action pane.
- Set the PYTHONPATH variable(which is your site folder path):
- 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):
- Click OK and browse to your site.
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.
The other option is that changing AppPool identity of the web application to LocalSystem
as IIS manager.
Solution 4:
If your file permissions are correct, the problem might lie in your Application Pools settings.
- Go to IIS manager
- Click on your server's
Application Pools
tab - Click
Set Application Pool Defaults
... - Set the
Identity
underProcess Model
to LocalSystem
Post a Comment for "Error 500 While Running A Python Flask Application On IIS. How To Get The Actual Error"