Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Configure Windows 2008 Server IIS 7 Python CGI  (Read 3551 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
Configure Windows 2008 Server IIS 7 Python CGI
« on: July 26, 2014, 03:28:40 pm »
How do I configure Windows 2008 Server IIS 7 to allow Python CGI?
You can add new Python CGI Script Map in IIS 7 management UI from:

"Features View" -> "Handler Mappings"
Here are the steps how I make Python running in IIS 7:

1. Please make sure Python is installed properly.
2. Make sure CGI module is installed in IIS 7

Control Panel -> Programs -> Program and Features -> Turn Windows features on and off -> Go to Roles ->

Internet Information Services -> World Wide Web Services -> Application Development Features -> CGI module. (click Add Role Services then check CGI)

3. Add web application for Python, In IIS Manager, right click Default Web Site -> Add Application, setting Alias e.g.: PythonApp, and make it pointing to some folder like C:\PythonApp, then click OK

4. In Features View, open Handler Mappings, right click to Add Script Map

5. In Request path, put "*.py" as the script files extension, In Executable select "C:\Python26\Python.exe "%s %s"" (be sure to include double quotes around the '%s %s'), here is my Python installation path and its parameters, this is mentioned in the KB article, you can check what are these two parameters used for. Then giving the script mapping an appropriate Name, like Python. Click OK.

6. Create or copy a into the virtual directory (C:\PythonApp), you can copy the following Python code or download the zip file:

NOTE: For Python 3.0 you will need to add parentheses () to each of the print functions. IE print ("hello world").
Code: [Select]
print 'Content-type: text/html'

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>'
print '<BODY>'
print "<H1>Welcome to Markrowsoft</H1>"

print '</BODY></html>'

Python 3.0 example:

print ('Content-type: text/html\r\n\r\n' )

print ('<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>')
print ('<BODY>')
print ("<H1>Welcome to Markrowsoft</H1>")

print ('</BODY></html>') Download working python CGI source file here
« Last Edit: July 26, 2014, 03:30:58 pm by sajugovind »