I am using python version 3.8 and IIS 7.0. When I try to host my python web api on the IIS server it encounter with the FastCGI error. I have enable CGI in IIS and also added System.WebServer>>handlers>>Python FastCGI in my web config but still it gives same error. I have also checked the wfastcgi and flask are also successfully added.
-
wfastcgi is out-of-maintenance, https://stackoverflow.com/tags/wfastcgi/info – Lex Li Aug 15 '20 at 06:42
-
@Lex what would the other alternatives you can suggest to host python web API on IIS. – Rajat Nigam Aug 15 '20 at 07:50
-
HttpPlatformHandler or simply ARR. – Lex Li Aug 15 '20 at 12:27
-
We are using HttpPlatformHandler. – Rajat Nigam Aug 15 '20 at 15:08
-
No, you don’t. HttpPlatformHandler doesn’t use FastCGI and won’t give you any FastCGI errors. – Lex Li Aug 15 '20 at 15:11
-
What are the other ways to host python web api on IIS Server, you guide us in any ways. – Rajat Nigam Aug 15 '20 at 18:12
-
https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019#configure-the-httpplatform-handler You only need this section and ignore the FastCGI section. However, Microsoft seems to indicate Python on IIS is not supported completely (as the first warning on that page says), so you should switch to Linux. – Lex Li Aug 15 '20 at 22:43
2 Answers
follow below steps to configure iis flask app in iis:
1)install python
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)enable the cgi feature of iis:
5)open iis create a site.
6)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:
7)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):
8)Click OK and browse to your site.
Note: Do not forget to assign the iis_iusrs and iusr permission to the site folder and the python folder.

- 8,251
- 1
- 11
- 26
-
Thanks for your answer, Through this we are getting a great progress but still, we stuck at some point. We are getting this error: **bold** The FastCGI process exceeded configured activity timeout **bold**. We tried to increase the timeout in applicationHost.config but still got the same issue. – Rajat Nigam Aug 18 '20 at 13:26
-
@RajatNigam Go to %windir%\system32\inetsrv\fcgiext.ini and locate the ActivityTimeout parameter; copy it into the [php] section. Change the parameter to whatever value you would like, and also make sure that it is not commented out. Restart IIS and you should be good. activityTimeout can be also set (IIS7 and above) from the IIS Manager under the server/IIS/FastCGI Settings/Edit.[image](https://i.imgur.com/W6swoqK.png) – Jalpa Panchal Aug 19 '20 at 09:22
-
This is not going to work. Were you enter wfastcgi.py, I get a pop up that says you can only specify a dll or exe file. – max Nov 24 '20 at 20:42
You had to put both parameters in double quote separated by |
e.g.
"c:\python39\python.exe" | "c:\python39\Lib\site-packages\wfastcgi.py"
or put the whole path in ""
after pasting it.

- 175,061
- 34
- 275
- 318

- 1
- 1