I have a python CGI script which takes form input x andy (integers) and passes it to a C++ executable using subprocess in which the program writes the sum of the two values to a text file.
The code works fine on my local machine.  However, after much testing ,I found that whenever I run this program on my server (in /var/www) and attempt to write the file some kind of error occurs because I get the "Internal Server Error" page.
The server is not mine and so I do not actually have sudo privileges.  But from putty, I can manually run the executable, and it indeed writes the file.
My guess is I have to somehow run the executable from the python script with some amount of permission, but I'm not sure.  I would appreciate any suggestions!
EDIT:
@gnibbler:  Interesting, I was able to write the file to the /tmp directory with no problem.  
So I think your suggestions are correct and the server simply won't allow me to write when calling the script from the browser.
Also, I cannot access the directory with the error logs, so I will have try to get permission for that.
Either the environment is different (maybe it's trying to write to the wrong dir) or more likely, the cgi isn't running as the same user that you are logging in as.
For example, it's fairly common for cgi scripts to be executed as "nobody" or "www" etc.
You could try getting the cgi to write a file into /tmp. That should at least confirm the user the cgi is running as
Unable to write to file programmatically on linux server