More Fun With MySQL and Images
Victor Subervi
victorsubervi at gmail.com
Thu Apr 17 10:52:39 EDT 2008
Never mind. Apparently, these tags throw it for that loop:
print '<html><body>\n'
I´m surprised they would, but gratified I found the problem.
Victor
On Thu, Apr 17, 2008 at 9:42 AM, Victor Subervi <victorsubervi at gmail.com>
wrote:
> Hi again:
> Here is my code, an edit of Gabriel´s:
>
> #!/usr/local/bin/python
> import cgitb; cgitb.enable()
> import MySQLdb
> def test():
> host = 'host'
> db = 'db'
> user = 'user'
> passwd = 'pass'
> db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> cursor= db.cursor()
> cursor.execute('select pic1 from products where id="2";')
> content = cursor.fetchall()[0][0].tostring()
> f = open("somefile.jpg", "w")
> f.write(content)
> f.close()
> print 'Content-Type: image/jpeg\r\nContent-Length: %d\n' % len(content)
> print '<html><body>\n'
> print content
> print '</body><html>\n'
> cursor.close()
>
> test()
> Now, when I surf to the url of this script, it prints out garbage that is
> a literal of the image, but not the image itself. However, if I surf to
> ¨somefile.jpg¨, I see the image!! Am I losing my mind?? What´s wrong here?
> TIA,
> Victor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080417/f491dd47/attachment.html>
More information about the Python-list
mailing list