<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Victor Subervi wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi;<br>
I've determined the problem in a script is I can't open a file to write it:<br>
script = open(getpic, "w") # where getpic is already defined<br>
Here are the permissions:<br>
-rwxr-xr-x 1 root root 4649 Nov 10 12:31 start.py<br>
What am I doing wrong?<br>
TIA,<br>
Victor<br>
<br>
<br>
</blockquote></div>
Wrong?<br>
<br>
1) you don't specify the environment, python version, OS, etc.<br></blockquote><div>python 2.4.3<br>CentOS 5.4 final <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2) you don't show the error traceback<br></blockquote><div>because there are none <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
3) you don't indicate the value of getpic at the time this statement executes<br></blockquote><div>As mentioned earlier, it increments:<br>getpic1.py<br>
getpic2.py<br>getpic3.py<br>getpic4.py<br>getpic5.py<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
4) you don't indicate what the current working directory is, os.getcwd()<br></blockquote><div>/var/www/html/<a href="http://angrynates.com/stxresort/cart">angrynates.com/stxresort/cart</a> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
5) you don't indicate what directory the start.py is located in<br></blockquote><div>ditto <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
6) you don't indicate which user is executing this script (only root can write to it)<br></blockquote><div>Help me on this. All scripts are owned by root. Is it not root that is executing the script? <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
7) you don't tell what the filename of the script is, specif. if it's called start.py </blockquote><div>yes, start.py <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
8) you don't say what happens if you do an open(getpic, "r"), or os.path.isfile(getpic)<br></blockquote><div>It doesn't like either of those. Goes to the except in the try.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
By the time you answer each of those questions, you may notice the answer to your own question.<br></blockquote><div><br>I wish that were so. I have written a little script that does nothing but test the line in question [open(getpic, 'w')] and that works. Here's a bigger code snippet with the entire try clause:<br>
<br> if 14 < x < 20: # This just shows that it's a pic, not some other type of data<br> y += 1<br> w += 1<br> try: # It does this, because I've printed 'getpic1.py' etc.<br>
getpic = "getpic" + str(w) + ".py"<br> try:<br> os.remove(getpic)<br> except:<br> pass<br> code = """#! /usr/bin/python<br>
import cgitb; cgitb.enable()<br>import MySQLdb<br>import cgi<br>import sys,os<br>sys.path.append(os.getcwd())<br>from login import login<br>def pic():<br> user, passwd, db, host = login()<br> form = cgi.FieldStorage()<br>
db = MySQLdb.connect(host, user, passwd, db)<br> cursor= db.cursor()<br> sql = "select pic%s from products where ID=%s;"<br> cursor.execute(sql)<br> content = cursor.fetchone()[0]<br> cursor.close()<br> print content<br>
print 'Content-type: image/jpeg'<br>print<br>pic()""" % (str(w), str(i))<br> script = open(getpic, "w") # I've deleted everything below this line to the except to test<br>
script.write(code)<br> print '<td><input type="hidden" name="%s" />\n' % str(x)<br> os.chmod(getpic, 0755)<br> print '<img src="%s" width="100"><br /><br /></td>\n' % (getpic)<br>
count2 += 1<br> except:<br> print '<td>nope</td>'<br> else:<br> print '<td>%s</td>\n' % (field)<br> x += 1<br></div>
</div><br><br>TIA,<br>V<br>