More & More Fun w/ Pics & MySQL

Victor Subervi victorsubervi at gmail.com
Fri Oct 16 21:23:31 CEST 2009


Hi;
Okay, here's the code:

#! /usr/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
def pic():
  user, passwd, db, host = login()
  form = cgi.FieldStorage()
  db = MySQLdb.connect(host, user, passwd, db)
  cursor= db.cursor()
  sql = "select pic1 from productsX where ID=1;"
  cursor.execute(sql)
  content = cursor.fetchone()[0]
  cursor.close()
  return content
print 'Content-type: image/jpeg'
print 'Content-Encoding: base64'
print
print pic().encode('base64')
print '</body></html>'

This will print all sorts of crap to the screen. I know it's an image,
because for some reason "occasionally" it once upon a time today printed the
actual image to the screen when I had these lines last:

print 'Content-type: text/plain'
#print 'Content-type: image/jpeg'
print
print pic()
print '</body></html>'

Notice the commented out line was essential, but it doesn't matter any more
because the tempermental python interpreter gods changed their attitude
toward this particular code snippet. Good grief. At any rate, this stupid
code worked fine before the last problem that way-laid me for 2 days, and
now it doesn't want to work again. What gives?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091016/80602a1f/attachment.html>


More information about the Python-list mailing list