Solved

mod_python permissions

Posted on 2004-08-08
7
829 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:confusedmoron
7 Comments
 
LVL 9

Expert Comment

by:rjkimble
ID: 11749539
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.
0
 
LVL 3

Expert Comment

by:pYrania
ID: 11750533
you also might check if the user apache is allowed to write to the file (file system permissions).
0
 

Author Comment

by:confusedmoron
ID: 11771210
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  
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:PaulS_III
ID: 11775763
Make sure that mytest.py is owned by the same user as apache and that it is executable by that same user
0
 

Author Comment

by:confusedmoron
ID: 11778854
Linux:/var/www/py# ls -l
-rwxr-xr-x    1 webuser  webuser       486 Aug  7 17:40 mytest.py
still cannot be found?
0
 

Author Comment

by:confusedmoron
ID: 11840022
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?
0
 
LVL 9

Accepted Solution

by:
rjkimble earned 250 total points
ID: 11840531
Use CGI. The cgi module has some helpful functions.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question