Serving Python scripts with CGIHTTPServer on Mac OS X

I am trying to configure Python CGIHTTPServer on Mac OS X to be able to serve CGI scripts locally, but I seem to be unable to do this.

I have 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 works fine with the shell, and for this I use a script using the CGIHTTPServer :

 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, the transition to localhost:8000 just serves for the contents of the script, and not for the result (i.e. returns code, not output).

What am I doing wrong?

+4
source share
1 answer

The paths in cgi_directories mapped to part of the URL path, not the actual path to the file system. Setting it to ["/"] or [""] is likely to work better.

+4
source

All Articles