Anyone who can configure Python using IIS? Tried to figure it out, but it doesn't work, and it drives me crazy. I see many examples, but I cannot get it to work.
Here is my setup
- Windows 2008R2
- IIS 7.5 (7.5.7600.16385)
- wfastcgi.py (2.2.0)
- Flask (0.10.1)
- Python (3.5.1)
Python + Flask Web Application Path
C:\inetpub\wwwroot
Below are the steps that I followed:
- Verify that the CGI windows feature is installed.
An application with the following values has been added in the IIS manager of the dedicated web server and in the FastCGI settings:
Full Path: C:\python35\python.exe Arguments: C:\inetpub\wwwroot\wfastcgi.py Environment Variable Collection: PYTHONPATH: C:\inetpub\wwwroot\ WSGI_HANDLER: app.app WSGI_LOG: C:\logs\app.txt
Created a website called MyWebSite pointing to C: \ inetpub \ wwwroot
In the display settings of the handler for the website, a mapping of modules for FastCgiModule has been added:
Request path: * Module: FastCgiModule Executable: C:\python35\python.exe|C:\inetpub\wwwroot\wfastcgi.py Name: FlaskHandler
A Simple Python application using Flask found on the Internet and added it to the root folder on the Internet. So, in C: \ inetpub \ wwww there are only 3 files: app.py, web.config and wfastcgi.py
web.config
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appSettings> <add key="PYTHONPATH" value="" /> <add key="WSGI_HANDLER" value="app.app" /> <add key="WSGI_RESTART_FILE_REGEX" value="(?i).*\.(py|cnf|config)$" /> </appSettings> <system.webServer> <handlers> <add name="FlaskHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\python35\python.exe|C:\inetpub\wwwroot\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" /> </handlers> </system.webServer> </configuration>
app.py
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello from FastCGI via IIS!" if __name__ == "__main__": app.run()
applicationHost.config:
global module:
<add name="FastCgiModule" image="%windir%\System32\inetsrv\iisfcgi.dll" />
module section:
<add name="FastCgiModule" lockItem="true" />
system web server section:
<section name="fastCgi" allowDefinition="AppHostOnly" overrideModeDefault="Deny" /> ... <fastCgi> <application fullPath="C:\Python35\python.exe" arguments="C:\inetpub\wwwroot\wfastcgi.py"> <environmentVariables> <environmentVariable name="PYTHONPATH" value="C:\inetpub\wwwroot\" /> <environmentVariable name="WSGI_HANDLER" value="app.app" /> <environmentVariable name="WSGI_LOG" value="c:\logs\my_log.txt" /> </environmentVariables> </application> </fastCgi>
So for some reason this is not working properly.
This is what I experience:
HTTP Error 500.0 - Internal Server Error C:\python35\python.exe - The FastCGI process exited unexpectedly
What I tried.
The handler script for the handler does not seem to be called correctly. It seems to be called, though, because when I change the value to something else, I get an error message:
HTTP Error 500.0 - Internal Server Error <handler> scriptProcessor could not be found in <fastCGI> application configuration
I thought it was an access issue, so I made sure the NETWORK SERVICE account has Read & Execute. I even gave each account full control. I believe NETWORK SERVICE is an account that requires permission.
I added registration to exit debugging information in app.py. I did not receive registration information in order to be able to write to the log file. I'm not sure how wfastcgi.py uses IIS configurations, even if I added it to web.config to configure the location of the log file. Perhaps if the Processor script is actually called, it will eventually configure it. But looking at the code, it seems to use a system environment variable, so I just added the value WSGI_LOG as the OS environment variable. Still does not log debugging information in the log file.
So, I tried to run the python executable with the wfastcgi file as an argument right on the command line and it seems to work as expected by entering a while loop while waiting and waiting for the request. And it also logs debugging information in the log file.
python.exe c:\inetpub\wwwroot\wfastcgi.py
And when I start the python server, it works when I go to localhost: 8081 in the browser, so I suspect this is a configuration issue.
python app.py runserver 0.0.0.0:8081
So what's going on. I have no ideas. Any help would be appreciated.
Thanks! It drives me crazy.