Link to home
Start Free TrialLog in
Avatar of confusedmoron
confusedmoron

asked on

mod_python permissions

This is giving me a headache. I have a simple script that opens a file and writes to it.
Something called foo.py that looks like this:

file = open("foo.txt","a")
file.write("Cheese and Killer Rabbits")
file.close()

But this just gives me:
Mod_python error: "PythonHandler foo"

Traceback (most recent call last):

  File "/usr/lib/python2.1/site-packages/mod_python/apache.py", line 193, in Dispatch
    result = object(req)

  File "/var/www/py/create.py", line 49, in handler
    file = open("foo.txt","a")

IOError: [Errno 13] Permission denied: 'foo.txt'

I need to get it so that Apache will recgonise all files ending in .py as python files and allow me to have proper permissions to write and change files.

I have something like this setup so far in Apache:
<Directory /var/www/py/>
    AddHandler python-program .py
    PythonHandler foo
    PythonDebug On
</Directory>

I know that only will work for foo.py, but the other setup:
AddHandler pythong-program .py
PythonHandler mod_python.publisher
just doesn't work at all. When I try to access files with that in apache it says they cannot be found.

I am running Apache as webuser who has full permissions over the directory /var/www/py/. When logged on as webuser I can do anything I want in the directory and when I use PHP I can also read/write etc.

Any ideas?
Thanks.
Avatar of rjkimble
rjkimble

According to this page:

http://www.modpython.org/live/current/doc-html/inst-prerequisites.html

You need to use Python 2.2.1 or later. Earlier versions of Python will not work. It appears from your posting that you're using Python 2.1.

Also, do you know for sure that the file you're trying to open is located in the directory you think it is? You might want to look at the output of os.path.abspath( 'foo.txt' ) just to be sure.
you also might check if the user apache is allowed to write to the file (file system permissions).
Avatar of confusedmoron

ASKER

Ok, I just upgraded python to 2.3.4 and still the same old problem with mod_python.publisher.
What happens is, when that option it enabled, even though I can see it in the directory listing, my python files just return
Not Found

The requested URL /mytest.py was not found on this server.
But it IS there
mytest.py               07-Aug-2004 17:40  486  
Make sure that mytest.py is owned by the same user as apache and that it is executable by that same user
Linux:/var/www/py# ls -l
-rwxr-xr-x    1 webuser  webuser       486 Aug  7 17:40 mytest.py
still cannot be found?
What I need is to be able to send data from a html to a python script.
 I know you can send data from inside one script to another via urllib2 but how to send data from html form without mod_python?
ASKER CERTIFIED SOLUTION
Avatar of rjkimble
rjkimble

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial