Solved

mod_python permissions

Posted on 2004-08-08
7
819 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

895 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

17 Experts available now in Live!

Get 1:1 Help Now