[mod_python] File access is not the way it used to be

Deron Meranda deron.meranda at gmail.com
Mon Jun 12 11:30:42 EDT 2006

On 6/12/06, drs. Slinger Jansen <slinger at cs.uu.nl> wrote:
>  if I run python just like that I can easily write to files, as you do,
> using such simple things as:
>  fp = open('debugCommCenter.out', 'w')
>  However, when these are in a server of mod_apache, nothing happens. Am I
> blocking file access or something? Is it a permission problem, and if so,
> how can I fix it? I've been looking for the solution on the list, and others
> say that adding the file dir to it should work. I did that too, but then
> still it doesn't work:
>  fp =
> open('d:\\xampp\\htdocs\\pytest\\debugCommCenter.out', 'w')

Do you get any error messages?  Do your mod_python handlers work
correctly otherwise?  Anyway, it could be permissions, because
your handlers are running as the Apache user.

Under modern Linuxes, the most likely cause is SElinux profiles.
Check the /var/log/messages log file for avt: denied messages.

Under Windows it could perhaps be an ACL permission (although
I don't know Windows very well).

Try perhaps to open and write to a different pathname, one that is
likely to have open permissions such as /tmp or C:\\Windows\Temp.

One other thing, when writing to files from within a mod_python
handler, you need to worry about concurrent file access.  Both by
multiple threads as well as multiple processes.  Opening files
in append-mode and using appropriate locking mechanism is
probably warranted.

And if all you want is to output some debugging messages,
consider using mod_python's apache.log_error() function instead.
Deron Meranda

More information about the Mod_python mailing list