User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,750 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,442 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 2863 | Replies: 3
Reply
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

simple cgi script issue

  #1  
May 27th, 2005
Hey there, i need some help with a simple cgi script.
i cannot get it to write output to a file.
here is the script.
#!/usr/bin/python

import cgi

form = cgi.FieldStorage()
Customer = form['Customer'].value
Field = form['Field'].value

data = [Customer, Field]


reshtml = """Content-Type: text/html\n
<html>
 <head><title>Customer Data</title></head>

 <body>
  <h1>Customer Data</h1>
  <p>Here ya go</p>
 </body>
</html>"""


print reshtml + 'Customer =' + data[0]
print '    ' + '    Field = ' + data[1]

# this is where the script fails to do anything....
OutFile = open("/home/nephish/Test.txt", "w")
OutFile.write("Here is a spot of text to input")
OutFile.close

it works, in that it returns the correct info to the browser,
but it does not write a text file.
i need to be able with this script to store on my disk what is input
in the html form.

any suggestions ?
Edit/Delete Message
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 173
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: simple cgi script issue

  #2  
May 27th, 2005
I ran a quick test and on my Windows XP Box it seems to be the file path it balks at. I had to give it the full file path (or at least back to where python.exe sits)
[php]
try:
# needs full file path!
OutFile = open("/home/nephish/Test.txt", "w")
OutFile.write("Here is a spot of text to input")
OutFile.close()
print "File successfully written"
except IOError:
print "Cannot open file for writing"
[/php]
May 'the Google' be with you!
Reply With Quote  
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

Re: simple cgi script issue

  #3  
May 27th, 2005
OK, Here is what i got.
i got the correct text back when i submitted the form
then it printed out
"Cannot open file for writing"
i wonder if its a permissions issue, but i am running this from the user
'nephish' so perhaps its something else.

thanks, by the way.
Reply With Quote  
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

Re: simple cgi script issue

  #4  
May 27th, 2005
OH Hey, it was a permission problem.
i made a directory off root called /files and did a chmod 777 to it
rewrote the path to /files and ran it again and it worked this time.
thanks!

back in action....
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 8:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC