python.exe – The FastCGI process exited unexpectedly

Question:

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 FilesPython38python.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:inetpubhistoryCFGHISTORY_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 FilesPython38python.exe|C:Program FilesPython38libsite-packageswfastcgi-3.0.0-py3.8.eggwfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <security>
            <authentication>
                <windowsAuthentication enabled="true" />
                <anonymousAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
    <appSettings>
       <add key="PYTHONPATH" value="C:inetpubwwwrootflaskr" />
       <add key="WSGI_HANDLER" value="__init__.app" />
       <add key="WSGI_LOG" value="C:inetpubwwwrootflaskrwfastcgi.log" />
    </appSettings>
</configuration>
Asked By: midlll

||

Answers:

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-32python.exe|C:Python37-32Libsite-packageswfastcgi.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 By: Jalpa Panchal

Check whether the production version of python and latest installed version of python in your machine, you have to install product version (version with in which you have developed your web app) and configure the fastcgi and handlers as it is.

Answered By: Sharad Bee

My issue was that I could run Flask app through cmd/PowerShell, but as soon as I ran it through IIS, it was returning above error with error code 0x00000067. I tried a lot of different things, including setting permissions etc. I finally solved it, by re-installing Python (3.9.6 in my case). I installed it for all users (via Advanced options), in folder C:Python39 (I was careful not to put it in C:Program Files, as some people reported issues with double quotes).

Answered By: Lucas

I was trying to install a different path other than Windows C. I got the same error. Then I successfully installed it on the E drive by making the following settings.

You can check the link below

https://mtuseeq.medium.com/how-to-deploy-flask-app-on-windows-server-using-fastcgi-and-iis-73d8139d5342

Answered By: Koray Ergin