I’ve just started playing with python with the intent of building android apps. As such this may be obvious to the seasoned python programmer, but nonetheless was not too terribly obvious to me at first.
After creating a CGI script to run I noticed that when the browser would execute the script I would get a 200 OK response from the browser, but the page was empty. Upon checking the terminal I received the following error:
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/http/server.py”, line 1059, in run_cgi
os.execve(scriptfile, args, env)
OSError: [Errno 13] Permission denied
The solution here is to give the script permission to be executed. To do this run the following line in the terminal (obviously I’m on a mac here):
chmod +x [name of you CGI script]
So just to keep things simple, assume you have a script in your Documents directory named ‘myScript.py’. You would execute the following in the terminal:
Documents myComputer$ chmod +x myScript.py
Essentially, this changes the mode of the specified script to be executable.
One thing to keep in mind, that dumbly wasted a few minutes of my time, is that if you have a terminal window open running the python server you cannot perform the above execution in that window. Make sure you open a new terminal window and execute on the command line.