String Literal to Blob
victorsubervi at gmail.com
Wed Apr 9 16:54:18 CEST 2008
On Wed, Apr 9, 2008 at 10:24 AM, Steve Holden <steve at holdenweb.com> wrote:
> Victor Subervi wrote:
> > On Wed, Apr 9, 2008 at 1:14 AM, Gabriel Genellina
> > <gagsl-py2 at yahoo.com.ar <mailto:gagsl-py2 at yahoo.com.ar>> wrote:
> Now all you have to do is what I told you in the first place, which is
> to remove the print statements before and after "print content".
That is what I figured after I sent the email. However, I had tried that
with a test script and the working script, with bad results. Here is the
test script that should have worked flawlessly:
print "Content-type: image/jpeg\r\n"
host = 'host'
db = 'bre'
user = 'user'
passwd = 'pass'
connection = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
cursor = connection.cursor()
cursor.execute('select img from photo where id="7";')
content = cursor.fetchall()
print "Content-Type: image/jpeg\nContent-Length: %d\n" % len(content)
This prints out the URL as an image! No idea why. But it does not produce
the desired image.
The following is the heart of the script for display. I tried entering the
Content-type where indicated, but it produces everything up to the image,
then produces the result of code from the exception...
cursor.execute('select id from products where category="' + category +
'" order by sort_factor desc, price desc;')
ids = cursor.fetchall()
if len(ids) != 0:
for id in ids:
for d in id:
cursor.execute('select * from products where id = ' + str(d) +
col_fields = cursor.fetchall()
if lang == 'es':
print '<b>ID: </b>', col_fields, '<br />'
print '<b>Nombre: </b>', col_fields, '<br />'
print '<b>Título: </b>', col_fields, '<br />'
print '<b>Descripción: </b>', col_fields, '<br />'
print '<b>Precio: </b>', col_fields, '<br />'
print '<b>Recámaras: </b>', col_fields, '<br />'
print '<b>Baños: </b>', col_fields, '<br />'
content = col_fields.tostring()
print "Content-Type: image/jpeg\nContent-Length: %d\n" %
print content, '<br /><br />'
if lang == 'es':
print 'Lo siento. Todavía no tenemos propiedades para enseñarse en la
categoría de ', category, '.\n<br /><br />'
> You are NOT generating HTML, you are generating a JPEG image.
I am producing both, and this is causing me confusion.
BTW, when we are finally done with this, I will write a nice how-to (since
there is not one in python, while php has some nice ones) on how to do this,
and give you and Gabrielle all your due credit. I will post it to this list,
because that is sure to rank highly in google right away.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list