Hey there. Here is the deal.... i have a script that is supposed to
open a file based on criteria from a web form.
i cant seem to get it to work though.

here is the code:

form = cgi.FieldStorage()
DataRecord = form['DataTime'].value
Customer = form['CustName'].value # should be automatically filled in

print "Content-Type: text/html\n\n"

WorkingFile =
all_lines = WorkingFile.readlines()
for line in all_lines:
	print line

here is the error:
WorkingFile undefined, builtin open = <type 'file'>, Customer =
'tenderloin', DataRecord = 'Tue Jun 7 20:13:35 2005.txt'

IOError: [Errno 2] No such file or directory:
'/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun 7 20:13:35
args = (2, 'No such file or directory')
errno = 2
filename = '/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun
7 20:13:35 2005.txt'
strerror = 'No such file or directory'

here is the deal.... the file is there ! i run similar code in idle and
it works.
i just dont get it. it isn't a permissions issue, its chmod 777 all
the way.
i gotta find out why this is goofing on me...

please help me!

Re: need some help with a cgi app 80 80

Add the test line
print "/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord
WorkingFile = open("/var/www ...

What comes up as full file path?

I know that spaces in a folder or filename are trouble!

Re: need some help with a cgi app 80 80

Well, it printed exactly that....
printed it out like a string

/var/www/stretch/web_root/SidCrops/gritty/Sun Jun 5 18:52:55 2005.txt

it did get the two variables right.

i guess we are having a difficulty with empty spaces.

ok, i also tried from the interpereter and got the same error.
IDLE told me the file does not exist also...... and .... yes, it does.
so.... this file is based (obviously) on a timestamp. maybe i should format the way its put out. here is how i am doing it right now

from time import time, ctime
the_time = ctime(time())
try:    #Make the customer directory and create a data file by a timestamp name
	OutFile = open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+the_time+".txt", "w")
	print "File created successfully  "
except IOError:
   	print "IO Error"

this works to create a file that another script is able to open and write to
at a later stage in the app. Thats whats weird .


Re: need some help with a cgi app 80 80

My experience with Dev-C++ and some of my Python programming tells me to avoid spaces in folder and file names with Microsoft boxes.

I would format the timestamp with time.strftime() to eliminated spaces. Give it a try, if it works you are wiser.

Re: need some help with a cgi app 80 80

ok will do when i get back to the house.
i'll let you know how it turns out.

Re: need some help with a cgi app 80 80

strftime was the key.
all working now.
thanks a million.
your'e awesome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.