I am running the following command from my home directory:
python -m CGIHTTPServer
Traceback (most recent call last):
File "/usr/lib/python2.7/CGIHTTPServer.py", line 251, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 13] Permission denied
student@bandersnatch:~$ ls -lhR
drwxr-xr-x 2 student student 4.0K Jun 13 18:38 cgi-bin
drwxr--r-- 2 student student 4.0K Jun 10 2004 kalpy
-rwxrwxrwx 1 student student 2.0K Jun 13 12:37 test.html
-rwxr-xr-x 1 student student 31 Jun 13 18:38 test.py
~$ which python
Are you, by any chance, running the process as root?
If you use the source, you will see in
CGIHTTPServer.py, just before calling
try: os.setuid(nobody) except os.error: pass
That is, it will run the CGI script as nobody, if it is able to change the UID, that is if it is root. If it is not root, this call will most likely fail, and pass on.
So my guess is that you are running the server as root, so the script is run as nobody, but this user doesn't have access to the script. Which is expected, as you say that it is in your home dir.
Two solutions that I can think of: