[Tutor] How to let IIS support Python script?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun, 12 Aug 2001 10:03:39 -0700 (PDT)


On Sun, 12 Aug 2001, xiaowp wrote:

> I want to write CGI programming using Python (web server is IIS 5.0).
> How to configure my IIS (or Apache) to support Python script. I have
> read the related paragraph of "Learning Python" (Mark Lutz & David
> Ascber, O'Reilly), but I cannot find the answer.

[Completely off-topic warning: if you plan to run an IIS system, please
make sure you have it patched to immunize it:

    http://www.eeye.com/html/Research/Advisories/AD20010618.html
]



To get Apache to support Python as a CGI language, look for an "AddHandler
cgi-script" line in your apache configuration line.  It'll look something
like this:


    # To use CGI scripts:
    AddHandler cgi-script .cgi .pl .py

If we place ".py" in that line, then we'll be able to run '.py' Python CGI
programs.

Apache is set up by default to only run .cgi programs in a specific
directory called 'cgi-bin', which can be found if we search around for
the "ScriptAlias" directories in the Apache configuration file.  For
example, here's one typical entry on a Unix system:

     ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"

It should be very similar to an entry on a Windows system.  You can add
more ScriptAliases so that you can place cgi programs in other
directories.



I don't know personally how to set things up on IIS, but there's an
entry in the FAQ wizard, which you can find here:

    http://www.python.org/cgi-bin/faqw.py

Here's what the FAQ says about setting up IIS and Python:


###
8.1. Using Python for CGI on Microsoft Windows Setting up the Microsoft
IIS Server/Peer Server: 

On the Microsoft IIS server or on the Win95 MS Personal Web Server you set
up python in the same way that you would set up any other scripting
engine. 

Run regedt32 and go to: 

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap 

and enter the following line (making any specific changes that your system
may need) 

.py :REG_SZ: c:\<path to python>\python.exe -u %s %s 

This line will allow you to call your script with a simple reference
like: http://yourserver/scripts/yourscript.py provided "scripts" is an
"executable" directory for your server (which it usually is by
default). The "-u" flag specifies unbuffered and binary mode for stdin -
needed when working with binary data 

In addition, it is recommended by people who would know that using
".py" may not be a good idea for the file extensions when used in this
context (you might want to reserve *.py for support modules and use *.cgi
or *.cgp for "main program" scripts). However, that issue is beyond this
Windows FAQ entry. 

Netscape Servers: Information on this topic exists
at: http://home.netscape.com/comprod/server_central/support/fasttrack_man/programs.htm#1010870 
###



Hope this helps!