python.exe - The FastCGI process exited unexpectedly

0

I have read all posts about this issue, here and on IIS forum, got it to the second page on Google too... and still can't get it to work.

I want to run Flask/Python app in IIS on Windows server 2016, but I keep getting this error:

HTTP Error 500.0 - Internal Server Error
C:\Program Files\Python38\python.exe - The FastCGI process exited unexpectedly

Detailed Error Information:
Module     FastCgiModule
Notification       ExecuteRequestHandler
Handler    FastCGI-Python
Error Code     0x00000002

I managed to get it work on my machine (Windows 10), but on server nope.

Environment

  • Windows Server 2016
  • IIS 10
  • Python 3.8
  • wfastcgi 3.0.0
  • Flask 1.1.1

I tried different versions of Python (3.6, 3.7, 3.8). On my Windows 10 it's running Python 3.7 and it's working fine. I can't use Python 3.4.2, as it was suggested in one of the posts, because Flask runs on 3.5 and higher and apparently wfastcgi works fine with Python 3.7 on my machine.

I granted full permissions to my application pool and to IIS_IUSRS on my web app folder and Python folder.

I have installed Microsoft C++ Build Tools too.

And the configuration of IIS has been shared from my machine to server through "Shared Configuration", so everything is the same. I just adapted some paths in config file.

I tried also running web app on Flask WSGI server for development and it worked fine.

Does anyone has a clue what more I can do? Any advice would be nice.

Thanks :)

EDIT: I've added a warning message from event viewer.

+ System 
- EventData 
  Path C:\inetpub\history\CFGHISTORY_0000000051 
   12000780 
--------------------------------------------------------------------------------
Binary data:
In Words
0000: 80070012    
In Bytes
0000: 12 00 07 80      

EDIT: Added web.config file

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <remove name="FastCGI-Python" />
            <add name="FastCGI-Python" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files\Python38\python.exe|C:\Program Files\Python38\lib\site-packages\wfastcgi-3.0.0-py3.8.egg\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <security>
            <authentication>
                <windowsAuthentication enabled="true" />
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
    <appSettings>
       <add key="PYTHONPATH" value="C:\inetpub\wwwroot\flaskr" />
       <add key="WSGI_HANDLER" value="__init__.app" />
       <add key="WSGI_LOG" value="C:\inetpub\wwwroot\flaskr\wfastcgi.log" />
    </appSettings>
</configuration>
python
iis
flask
windows-server-2016
wfastcgi
asked on Stack Overflow Feb 3, 2020 by Mirnesa Kovacevic • edited Feb 10, 2020 by Mirnesa Kovacevic

1 Answer

0

You could follow the below steps to configure python flask application in iis:

1)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.

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

pip install wfastcgi

wfastcgi-enable

3)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()

4)after creating an application to run it use below command:

python app.py

5)enable the cgi feature of iis:

enter image description here

6)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

7)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

8)Click OK and browse to your site.

enter image description here

Note: Do not forget to assign the iis_iusrs and iusr permission to the site folder and the python folder.

answered on Stack Overflow Feb 5, 2020 by Jalpa Panchal

User contributions licensed under CC BY-SA 3.0