Python, ASP, ADO, and Image string/binary problems

Shonn Gilson shonn at
Sat Mar 3 00:17:35 CET 2001

Okay, here it goes.
I have a site in ASP where I need to upload an image (already working) and
then make a thumbnail of it. The image is stored in a MS SQL Server
database, I'm using IIS5 (Win2k), and the python is Active State's with all
the COM functionallity added.
Here's what I'm trying to do:

<script runat="server" language="Python">
import os, sys
import PIL.Image
import StringIO

strSQL = "select * from [FILE] where FILE_Guid =
objConn = Server.CreateObject("ADODB.Connection")
objRS = Server.CreateObject("ADODB.Recordset")
objConn.Open (connection_string)
objRS.Open (strSQL,objConn,3,1)
bstrIn = objRS("FILE_File").value # returns a buffer, not a string
im =
im.thumbnail((128, 128))
bstrOut = StringIO.StringIO(), "JPEG",optimize=1,progressive=1)
Response.ContentType = 'text/html' #'image/jpeg'
Response.Write(" ")
#Response.Write ('size')
#Response.Write (`im.size`)

If I do a Response.BinaryWrite(bstrIn) I get the image in the browser but if
I do Response.BinaryWrite(bstrOut.getvalue()) I get spaces between every
character (I've seen this with unicode problems). It's not just an
incompatibility with Response.BinaryWrite because I've written the results
back to the database with the same results. It seems like it's a problem
with how python deals with strings.

Anyone have any ideas?

Thanks in advance


More information about the Python-list mailing list