I've attempted (strong emphasis on "attempt") to set up an application via IIS (6.1, Windows Server 2008 R1) that routes all requests through a python script. The end goal was to create a very light-weight API on the server.
Basically, I took the following steps:
- Added CGI feature to windows
- Created a new Application under the Default Web Site
- Added a handler mapping that accepts
c:\Python27\python.exe -u "c:\inetpub\wwwroot\testapi\cgiadapter.py"
- Set the virtual directory of the application to
- Set the physical path of the application to
To do a basic test, the following script was tested and works:
import cgi, cgitb # Detailed error logging to screen cgitb.enable() # Output basic response print 'content-type:text/plain' print print 'Hello World'
Then, I try to update the script to read in the request from stdin
import cgi, cgitb # Detailed error logging to screen cgitb.enable() # Attempt to read the raw request from CGI import sys request = sys.stdin.read() # Output basic response print 'content-type:text/plain' print print 'Hello World'
Suddenly, I receive the following error:
<type 'exceptions.IOError'>: [Errno 9] Bad file descriptor on the line containing
stdin considered a bad file?
Have I configured something incorrectly in IIS or is this a limitation to IIS? Or, perhaps, is the fact that the request is delivered via stdin an incorrect assumption?