[mod_python] Problem writing to file from handler

Gregory (Grisha) Trubetskoy grisha at modpython.org
Tue Jan 30 22:08:13 EST 2001


The difference is the current directory. CGI scripts are executed with the
directory where the script is located as current, with mod_python the
current directory is undefined. You need to specify full path to your file
when opening it.

Grisha

On Tue, 30 Jan 2001 oddmund.mogedal at accenture.com wrote:

> Hi,
> 
> I need to write to a file from within a script (called using publisher.py).
> For some reason, I am not allowed to write to the file, even though it
> exists and has write permission for everyone.
> (Yes, it is a security risk, but not in the environment where I will use
> it.)
> 
> I have tried the same thing using the cgi module, and then I am allowed to
> write to the file.
> Is there a difference in access rights to the file system between a script
> called from mod_python and a script called using CGI?
> 
> Does anybody know what is causing this problem?
> 
> Using mod_python: DOES NOT WORK
>     import getpass
> 
>     def omtest(req, username, file):
>         myfile = open("testom", 'wb')
>         myfile.write(file)
>         myfile.close()
>         return "%s\n%d\n%s\n" % (username, len(file), getpass.getuser())
> 
> Using cgi: WORKS OK
>     #!/usr/local/bin/python2.0
> 
>     import getpass
>     import sys
>     import cgi
> 
>     myfile = open("testom", 'wb')
>     form = cgi.FieldStorage()
>     name = form["name"].value
>     file = form["file"].value
>     myfile.write(file)
> 
>     print "Content-Type: text/html"
>     print
>     print name
>     print getpass.getuser()
> 
> 
> 
> 
> Oddmund
> 
> 
> 
> This message is for the designated recipient only and may contain
> privileged or confidential information.  If you have received it in error,
> please notify the sender immediately and delete the original.  Any other
> use of the email by you is prohibited.
> 
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
> 




More information about the Mod_python mailing list