Problem Displaying Pics

Victor Subervi victorsubervi at gmail.com
Thu Oct 8 17:30:16 CEST 2009


http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1
TIA,
V

On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury <rami.chowdhury at gmail.com>wrote:

> On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <
> victorsubervi at gmail.com> wrote:
>
>  print 'Content-Type: image/jpeg'
>> print 'Content-Encoding: base64'
>> print
>> print content.encode('base64')
>>
>> I did change it to text/plain, but I don't know how I'm supposed to
>> manually
>> decode it. Yes, it printed out a bunch of crap to the screen. I've gotten
>> that far before, and once I read "Adobe" something, so yes, it's an image.
>> TIA,
>> V
>>
>>
> Hopefully the 'crap' you're getting is the base64-encoded representation of
> your binary image -- you should be able to use Python to decode that, and
> then use any image viewer to verify that the JPEG is sound.
>
> Can you remind us of the URL where that code (with the text/plain content
> type) is running?
>
>
>
>  On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury <rami.chowdhury at gmail.com
>> >wrote:
>>
>>  On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi <
>>> victorsubervi at gmail.com> wrote:
>>>
>>>  I did that. In fact, just to make things easier, I wrote out exactly
>>> what
>>>
>>>> is
>>>> supposed to be rendered, as below:
>>>>
>>>> #!/usr/local/bin/python
>>>> import cgitb; cgitb.enable()
>>>> import MySQLdb
>>>> import cgi
>>>> import sys,os
>>>> sys.path.append(os.getcwd())
>>>> from login import login
>>>> user, passwd, db, host = login()
>>>> form = cgi.FieldStorage()
>>>> db = MySQLdb.connect(host, user, passwd, db)
>>>> cursor= db.cursor()
>>>> sql = "select pic1 from products where id='1';"
>>>> cursor.execute(sql)
>>>> content = cursor.fetchall()[0][0].tostring()
>>>> cursor.close()
>>>> print '''Content-Type: image/jpeg'''    # Only print one line
>>>>
>>>> Content-Encoding: base64
>>>> '''
>>>> print
>>>> print content.encode('base64')
>>>>
>>>>
>>>>  Just to reiterate what Gabriel and Carsten have pointed out, I'd
>>> suggest
>>> changing the last few lines of the script, as the comments below
>>> indicate:
>>>
>>> print '''Content-Type: image/jpeg''' # One header line
>>> print '''Content-Encoding: base64''' # Another header line. Note *no*
>>> blank
>>> line between them
>>> print                                # Blank line signals the end of the
>>> headers
>>> print content.encode(base64)         # Base64-encoded content comes
>>> *after*
>>> the blank line
>>>
>>> If you include extra blank lines after the headers, the browser will
>>> misunderstand where the binary image data begins, and so will see a
>>> malformed JPEG.
>>>
>>> If this doesn't work, I suggest changing the content-type header to
>>> text/plain and trying to manually decode and check the image data to
>>> ensure
>>> it's valid.
>>>
>>>
>>>
>>>  On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina <
>>>> gagsl-py2 at yahoo.com.ar
>>>> >wrote:
>>>>
>>>>  En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi
>>>>
>>>>> <victorsubervi at gmail.com> escribió:
>>>>>
>>>>> > print '''Content-Type: image/jpeg
>>>>> >
>>>>> > '''
>>>>> > print
>>>>> > print content
>>>>>
>>>>> On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina <gagsl-
>>>>> py2 at yahoo.com.ar>wrote:
>>>>>
>>>>> > That's still wrong. The output should be:
>>>>> >
>>>>> > - a line containing Content-Type: image/jpeg
>>>>> > - a blank line (no more!)
>>>>>       ^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>> > - the actual image data
>>>>>
>>>>> --
>>>>> Gabriel Genellina
>>>>> --
>>>>> http://mail.python.org/mailman/listinfo/python-list
>>>>>
>>>>>
>>>>>
>>>
>>> --
>>> Rami Chowdhury
>>> "Never attribute to malice that which can be attributed to stupidity" --
>>> Hanlon's Razor
>>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>>>
>>>
>
>
> --
> Rami Chowdhury
> "Never attribute to malice that which can be attributed to stupidity" --
> Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091008/8189cf67/attachment.html>


More information about the Python-list mailing list