file path & windows cgi

chris liechti cliechti at no.spam.gmx.net
Thu Sep 27 14:58:48 EDT 2001


scott at griffitts.com (Scott Griffitts) wrote in 
news:4c5f6fa.0109271019.19b0b896 at posting.google.com:

> Trying to read a file, this script works for me:
> 
> z = open('I:\\test\\test.txt')
> for x in z.readlines():
>     b = "%s%s" % (b,x)

why not "b = open('I:\\test\\test.txt').read()"

or at least use "string.join()": 

listoflines = open('I:\\test\\test.txt').readlines()
b = ''.join(listoflines)

> z.close()
> print b
> 
> But if I try and get the path to the file via an html form:
> 
> import cgi
> y = cgi.FieldStorage()
> z = open(y['getter'].value)
> for x in z.readlines():
>     b = "%s%s" % (b,x)
> z.close()
> print b
> 
> I get:
> 
> Traceback (most recent call last):
>   File "c:\inetpub\wwwroot\python\brow2.py", line 5, in ?
>     z = open(y['getter'].value)
> IOError: [Errno 22] Invalid argument: 'I:\\test\\test.txt'
> 
> Does anyone know what I'm missing here?  Thanks.

do you run this script from a webserver? maybe the server puts some 
restrictions for CGI scripts (like no file access). look at the module 
"rexec" to get an idea how such restrictions could be be implemented by the 
webserver. 

-- 
chris <cliechti at gmx.net>




More information about the Python-list mailing list