[Tutor] please help with simple python CGI script

aivars aivars868 at gmail.com
Fri Oct 24 16:25:21 CEST 2008


I am learning python.

I start the python CGI server like this:

python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core
Python Programming chapter 20.5)

The server starts in command prompt on windows XP by answering:
Serving HTTP on port 8000...

Next I want to run this simple CGI script (from Deitel Python How to
Program chapter 6). it is supposed to print out current date and time
in a browser

import time

def printHeader(title):
    print """Content-type: text/html

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >

<body>""" % title

printHeader("Current date and time")
print time.ctime(time.time())
print "</body></html>"

And The server prints the script text in the browser. It does not run
the script.
The server response is 200.
The script itself runs OK if being run from python/command line

I also could not run the script from wesley chun's book. I think also
because it seems the python cgi web server does not understand that it
should run the script and not to print it out in web browser

I am using python 2.5 on windows XP.

What I am missing?


More information about the Tutor mailing list