python.exe - The FastCGI process exited unexpectedly
Asked Answered
U

5

7

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>
Ulita answered 3/2, 2020 at 16:13 Comment(2)
It sounds like there was an access violation exception. What's the detailed error message in event viewer?Psychology
Hi @JokiesDing , in event viewer there's just a warning messages. I'll post it in edit of the post.Ulita
T
5

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.

Titograd answered 5/2, 2020 at 10:12 Comment(9)
Hi, thank you for your answer. I've done exactly all those steps two times already and didn't solve my problem.Ulita
@MirnesaKovacevic could you please share your sample code and web.config file? are you using the virtual environment? at the time of installation did you select to install for all users? make sure your application pool is using the application pool identity and anonymous authentication is enabled and remaining are disabled.Titograd
I'm using global python environment; yes, I have selected to install for all users. I'm using Windows authentication and that one is enabled, the rest are disabled; my application pool is using LocalSystem identity, because it works on my machine only if it's using LocalSystem as identity. I'll post web.config file when I'll have access to the server. Thanks :)Ulita
@MirnesaKovacevic what is your main python file? and when you install the python you get the prompt like imageDon’t trust this. Check the following manually .wfastcgi-enable and wfastcgi-disable exe present in the python environment / scripts folder. please refer this linkTitograd
I'm running simple "Hello World!", the same example like yours. But I noticed that when I run wfastcgi-enable, I get paths with double quotes... Applied configuration changes to section "system.webServer/fastCgi" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST" ""C:\Program Files\Python38\python.exe"|"C:\Program Files\Python38\lib\site-packages\wfastcgi-3.0.0-py3.8.egg\wfastcgi.py"" can now be used as a FastCGI script processor ... Can that be a problem?Ulita
@MirnesaKovacevic you need to use the wfastcgi.py from site-packages. did you check the above-posted link?Titograd
The problem was that the path had spaces in the name "C:\Program Files" and IIS doesn't allow double qoutes in web.config file. I reinstalled Python directly to "C:\Python38", folder without spaces in it's name. And it works now. Thanks for the effort answering me. :)Ulita
@MirnesaKovacevic if your issue is resolved then I request you to mark the helpful suggestion as an answer.Titograd
@JalpaPanchal where to place the web.config file?Angleworm
A
0

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.

Augury answered 16/6, 2021 at 12:14 Comment(0)
P
0

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

Plessor answered 27/10, 2021 at 12:51 Comment(0)
D
0

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

Decor answered 4/11, 2022 at 9:15 Comment(1)
Your answer could be improved by describing how to make the changes, not just link to an external site.Barmen
S
0

For me its Working when the Folder containng Python Exe file should provide permission for the users - IUSR and IIS_IUSRS .

Folder of Python : C:\Users\Administrator\AppData\Local\Programs\Python\Python311

Senate answered 1/8 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.