Can't Write File

Victor Subervi victorsubervi at gmail.com
Wed Nov 11 14:26:53 EST 2009


On Wed, Nov 11, 2009 at 1:20 PM, Benjamin Kaplan
<benjamin.kaplan at case.edu>wrote:

> On Wed, Nov 11, 2009 at 11:42 AM, Victor Subervi
> <victorsubervi at gmail.com> wrote:
> > On Wed, Nov 11, 2009 at 11:23 AM, Rami Chowdhury <
> rami.chowdhury at gmail.com>
> > wrote:
> >>
> >> On Wed, 11 Nov 2009 06:00:44 -0800, Victor Subervi
> >> <victorsubervi at gmail.com> wrote:
> >>
> >>> On Tue, Nov 10, 2009 at 4:33 PM, Dave Angel <davea at ieee.org> wrote:
> >>>
> >>>> Victor Subervi wrote:
> >>
> >>>> Wrong?
> >>>> 2) you don't show the error traceback
> >>>>
> >>> because there are none
> >>>
> >>>            try: # It does this, because I've printed 'getpic1.py' etc.
> >>>              getpic = "getpic" + str(w) + ".py"
> >>>              try:
> >>>                os.remove(getpic)
> >>>              except:
> >>>                pass
> >>
>

Ok, I rewrote the script so that it calls one file called "getpic.py" with
parameters:

#! /usr/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
form = cgi.FieldStorage()
w = form.getfirst('w', '')
i = form.getfirst('i', '')
def pic():
  user, passwd, db, host = login()
  form = cgi.FieldStorage()
  db = MySQLdb.connect(host, user, passwd, db)
  cursor= db.cursor()
  sql = "select pic%s from products where ID=%s;" % (w, i)
  cursor.execute(sql)
  content = cursor.fetchone()[0]
  cursor.close()
  print content
print 'Content-type: image/jpeg'
print
pic()

Now, the problem is that it doesn't print the picture. It prints only the
url. Please try:
http://angrynates.com/stcroixresort/cart/getpic.py?w=1&i=1
Now, if I go into mysql and the correct database and enter:
select pic1 from products where ID=1;
it starts printing out all sorts of crap (indicative of an image) and I have
to close my ssh client. So it's there, all right. So, here I am back to
trying to figure out how to get that stupid image to print. Please take a
look at the code above and advise.
TIA,
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091111/c1eae780/attachment.html>


More information about the Python-list mailing list