Solved

mod_python permissions

Posted on 2004-08-08
7
815 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now