More & More Fun w/ Pics & MySQL

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

Okay, here's the code:

#! /usr/bin/python
import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
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;"
  content = cursor.fetchone()[0]
  return content
print 'Content-type: image/jpeg'
print 'Content-Encoding: base64'
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 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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list