Saturday, August 15, 2009

Using Python Scripts with IIS 7

Here are the steps you should make if you want to use python scripts on IIS 7:

  • Please make sure Python is installed properly or refer to Python Notes – 1 : Setup for installation steps.
  • Make sure CGI module is installed in IIS 7.

Control Panel -> Programs -> Program and Features -> Turn Windows features on and off -> Internet Information Services -> World Wide Web Services -> Application Development Features -> CGI module (Ensure that it is selected).

Screenshot Studio capture #1

  • Add web application for Python, In IIS Manager, right click Sites –> Add Web Site..

Screenshot Studio capture #2

  • In the Add Web Site dialog box, set Site name e.g.: PythonTest, and make it pointing to some folder like C:\PythonTest, then click OK

Screenshot Studio capture #4

  • In Features View, open Handler Mappings

Screenshot Studio capture #5

  • On the left pane click Add Script Map ...

Screenshot Studio capture #7

  • In Request path, put "*.py" as the script files extension, In Executable select "C:\Python25\Python.exe %s %s", or change it according to your Python installation path. (The two "%s" after the executable are required for console-based script interpreters but would not be required for an Internet Server API [ISAPI]-based script interpreter). Then give the script mapping an appropriate Name, like Python. Click OK.

Screenshot Studio capture #8

  • Create a test.py into the virtual directory (C:\PythonTest), and copy the following script into it.

print

print 'Status: 200 OK'

print 'Content-type: text/html'

print

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>' print '<BODY>'

print '<H1>This is a header</H1>'

print '<p>' #this is a comment

print 'See this is just like most other HTML'

print '<br>'

print '</BODY>'

No comments: