[mod_python] can I create files or directories?

Graham Dumpleton grahamd at dscpl.com.au
Thu Jun 2 02:18:31 EDT 2005

Josh Brown wrote ..
> I have mod_python set up and have some test sites up and running on my
> server.  I'm having problems using os.mkdir and opening files with 'w'
> permissions.  Are there additional security measures being taken by
> the mod_python apache module to not allow writing to files/or adding
> dirs/files to the server?
> My apache server is running with the user apache and group apache and
> the files and directories that I want to write to are writable by the
> apache user so I just wanted to make sure that the module wasn't
> stopping me from doing this.

If the directories are truly writable to the user Apache runs as, next
thing would be whether you are using an absolute path to the directory
where you want to write the files. By default Apache usually runs in root
directory of the filesystem ie., '/'. Even that though you can't rely on.

In other words, you CANNOT open a file in same directory as handler by

  f = open("myfile","w")

Instead, you would need to say something like:

  directory = os.path.dirname(__file__)
  path = os.path.join(directory,"myfile")

  f = open(path,"w")

If that doesn't help, what is the actual Python exception being raised and
being displayed in the browser or in Apache error log file.


More information about the Mod_python mailing list