[Tutor] Setting up server for CGI

btkuhn at email.unc.edu btkuhn at email.unc.edu
Fri Oct 31 02:41:50 CET 2008


Hi everyone,

I am new to programming and have been programming with Python for
about 2.5 months. After learning the basics of the language I am
trying to teach myself CGI with Python. I've
come across a few resources that teach CGI, but I am having much
trouble setting up a
server to view CGI scripts on my browser (Note: some of terminology
may be wrong). I am running Windows XP with a Firefox browser.

Here is what I've tried so far:

I followed the instructions on a tutorial and created a "C:\cgihome"
server, and then
created the following file:

C:\cgihome\server\cgihttpserver.py

It contains the following code:
[CODE]
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["/cgi"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
[/CODE]

This is supposed to set up a basic server on my system. When I run
from the command line,
it seems to be working and displays the message "Serving at Port
8000".

According to the tutorial I should then be able to run CGI scripts by
saving them in
C:/cgihome/cgi , and then opening in the browser (after running the
server script on the
command line). So for instance I wrote this script:
[CODE]
#!c:\Python25\python.exe

print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""
[/CODE]
and saved it as C:\cgihome\cgi\cgitest.py . When I try opening it in
my browser, though,
I just get 404 error: "File not found". This shows up both in the
browser window and the
command prompt window. When I try using a plain .html file saved in
C:\cgihome instead, I
get the same error. I can't get anything to run. I'm sure I'm doing
something wrong, but
I don't know what. I have also tried downloading the Apache server as
well, but it is 10
times more complex than my simple server script, and geared towards
Linux users who know what they are doing.

Can someone please explain to me like I'm a child how to set up a
basic web server that I
can run CGI scripts on?

Thanks very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/706e2610/attachment-0001.htm>


More information about the Tutor mailing list