简体   繁体   中英

Serving Python scripts with CGIHTTPServer on Mac OS X

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 using 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, going to localhost:8000 just serves the content of the script, not the result (ie it gives back the code, not the output).

What am I doing wrong?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM