views:

24

answers:

1

I'm trying to set up Python's CGIHTTPServer on Mac OS X to be able to serve CGI scripts locally, but I seem to be unable to do this.

I've got a simple test script:

#!/usr/bin/env python

import cgi

cgi.test()

It has permissions -rwxr-xr-x@ and is located in ~/WWW (with permissions drwxr-xr-x). It runs just fine from the shell and I have this script to serve them usingCGIHTTPServer`:

import CGIHTTPServer
import BaseHTTPServer

class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
    cgi_directories = ["~/WWW"]

PORT = 8000

httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT

But when I run it, going to localhost:8000 just serves the content of the script, not the result (i.e. it gives back the code, not the output).

What am I doing wrong?

+2  A: 

The paths in cgi_directories are matched against the path part of the URL, not the actual filesystem path. Setting it to ["/"] or [""] will probably work better.

slowdog
yes! that did it! thanks!
thepandaatemyface