Net4geeks.com - Your Geek Source
 
   
 
     
 
 

Login to Forums

Login to post to forums and post news.





Lost Password?
No account yet? Register
Configure Windows 2008 Server IIS 7 Python CGI PDF Print E-mail
Written by Mark   

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 test.py 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").

 

print 'Content-type: text/html'
print

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 Updated ( Tuesday, 14 April 2009 )
 
< Prev   Next >

 
  net4geeks.com   net4psp.com   net4bikes.com