<a href="http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1">http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1</a><br>TIA,<br>V<br><br><div class="gmail_quote">On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury <span dir="ltr"><<a href="mailto:rami.chowdhury@gmail.com">rami.chowdhury@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>> wrote:<br>

<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
print 'Content-Type: image/jpeg'<br>
print 'Content-Encoding: base64'<br>
print<br>
print content.encode('base64')<br>
<br>
I did change it to text/plain, but I don't know how I'm supposed to manually<br>
decode it. Yes, it printed out a bunch of crap to the screen. I've gotten<br>
that far before, and once I read "Adobe" something, so yes, it's an image.<br>
TIA,<br>
V<br>
<br>
</blockquote>
<br></div>
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.<br>

<br>
Can you remind us of the URL where that code (with the text/plain content type) is running?<div><div></div><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury <<a href="mailto:rami.chowdhury@gmail.com" target="_blank">rami.chowdhury@gmail.com</a>>wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi <<br>
<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>> wrote:<br>
<br>
 I did that. In fact, just to make things easier, I wrote out exactly what<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
is<br>
supposed to be rendered, as below:<br>
<br>
#!/usr/local/bin/python<br>
import cgitb; cgitb.enable()<br>
import MySQLdb<br>
import cgi<br>
import sys,os<br>
sys.path.append(os.getcwd())<br>
from login import login<br>
user, passwd, db, host = login()<br>
form = cgi.FieldStorage()<br>
db = MySQLdb.connect(host, user, passwd, db)<br>
cursor= db.cursor()<br>
sql = "select pic1 from products where id='1';"<br>
cursor.execute(sql)<br>
content = cursor.fetchall()[0][0].tostring()<br>
cursor.close()<br>
print '''Content-Type: image/jpeg'''    # Only print one line<br>
<br>
Content-Encoding: base64<br>
'''<br>
print<br>
print content.encode('base64')<br>
<br>
<br>
</blockquote>
Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest<br>
changing the last few lines of the script, as the comments below indicate:<br>
<br>
print '''Content-Type: image/jpeg''' # One header line<br>
print '''Content-Encoding: base64''' # Another header line. Note *no* blank<br>
line between them<br>
print                                # Blank line signals the end of the<br>
headers<br>
print content.encode(base64)         # Base64-encoded content comes *after*<br>
the blank line<br>
<br>
If you include extra blank lines after the headers, the browser will<br>
misunderstand where the binary image data begins, and so will see a<br>
malformed JPEG.<br>
<br>
If this doesn't work, I suggest changing the content-type header to<br>
text/plain and trying to manually decode and check the image data to ensure<br>
it's valid.<br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina <<a href="mailto:gagsl-py2@yahoo.com.ar" target="_blank">gagsl-py2@yahoo.com.ar</a><br>
>wrote:<br>
<br>
 En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>> escribió:<br>
<br>
> print '''Content-Type: image/jpeg<br>
><br>
> '''<br>
> print<br>
> print content<br>
<br>
On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina <gagsl-<br>
<a href="mailto:py2@yahoo.com.ar" target="_blank">py2@yahoo.com.ar</a>>wrote:<br>
<br>
> That's still wrong. The output should be:<br>
><br>
> - a line containing Content-Type: image/jpeg<br>
> - a blank line (no more!)<br>
       ^^^^^^^^^^^^^^^^^^^^^^^^^<br>
> - the actual image data<br>
<br>
--<br>
Gabriel Genellina<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br>
<br>
</blockquote></blockquote>
<br>
<br>
--<br>
Rami Chowdhury<br>
"Never attribute to malice that which can be attributed to stupidity" --<br>
Hanlon's Razor<br>
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)<br>
<br>
</blockquote></blockquote>
<br>
<br>
<br>
-- <br>
Rami Chowdhury<br>
"Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor<br>
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)<br>
</div></div></blockquote></div><br>