[Zope] want to use external script to read a text-file and image in database and modify REQUEST

J Cameron Cooper zope-l at jcameroncooper.com
Sat Feb 25 13:41:47 EST 2006


Allen Huang wrote:
> Hi
>  
> I want to use external methods to read a text file and image in database 
> and modify the REQUEST
>  
> my code looks like this varible
> -----------------------
> def imageSetup(self, imageID, dataID, REQUEST):
>     import PIL.Image
>     from StringIO import StringIO
>  
>     # Get the original image and data in memory.
>     image=getattr(self, imageID)
>     imageData=getattr(self, dataID)
>     imageFile=StringIO(str(image.data))
>     imageDataFile=StringIO(str(imageData.data))
>     # open image and data file
>     im = PIL.Image.open(imageFile)
>     tfw = open(imageDataFile, "r")
>  
>     # assign data coordinate and image size to variables
>     imX,imY = im.size()
>     rX=float(tfw.readline())
>     tfw.readline()
>     tfw.readline()
>     rY=float(tfw.readline())
>     mnX=float(tfw.readline())
>     mnY=float(tfw.readline())
>     mxX=mnX+imX*rX
>     mxY=mnY+imY*rY
>  
>     # assign variables to REQUEST
>     REQUEST.set('resX', rX)
>     REQUEST.set('resY', rY)
>     REQUEST.set('minX', mnX)
>     REQUEST.set('minY', mnY)
>     REQUEST.set('maxX', mxX)
>     REQUEST.set('maxY', mxY)
>     REQUEST.set('pixelX', imX)
>     REQUEST.set('pixelY', imY)
> --------------------------------------
> but all I get is this
>  
> zope coercing to Unicode: need string or buffer, instance found
>  
> and the REQUEST variable is unchanged
>  
> I'm still new to external scripting so I don't know what the problem is
> (and I think there is a lot of it here)
>  
> so, could someone help me out??

It's likely that you're passing an object to a method that wants a 
string (probably an id). Without a traceback, it's impossible to say more.

Are you sure that the things you're passing in as ids are really ids and 
not the objects themselves?

		--jcc
-- 
Building Websites with Plone
http://plonebook.packtpub.com/


More information about the Zope mailing list