String Literal to Blob

Victor Subervi victorsubervi at gmail.com
Tue Apr 8 11:24:44 EDT 2008


Hi:
I am able (finally) to upload an image to the database. However, when I try
to retrieve it, I get a string literal. Here is my code:

#!/usr/local/bin/python
import cgitb; cgitb.enable()
import MySQLdb
def test():
  host = 'mysqldb2.ehost-services.com'
  user = 'user'
  passwd = 'pass'
  db = 'bre'
  db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
  cursor= db.cursor()
  cursor.execute('select pic1 from products where id="3";')
  content = cursor.fetchall()
#  print 'Content-Type: image/jpeg\r\nContent-Length: %d\n' % len(content)
  print 'Content-Type: image/jpeg\r\n'
  print '<html><body>\n'
  print content
  print '</body><html>\n'
  cursor.close()

test()
(Apparently, Plesk doesn´t like if __name__ == '__main__': )
The commented out line gives me a leading less than sign...and that´s it.
What do?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080408/1c93be2f/attachment.html>


More information about the Python-list mailing list