Solved

mod_python permissions

Posted on 2004-08-08
7
837 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
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…

696 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