[reportlab-users] Puzzling Error

Andy Robinson reportlab-users@reportlab.com
Tue, 5 Nov 2002 16:55:51 -0000

> exceptions.AttributeError
> 'unicode' object has no attribute 'write'
> <traceback object at 0x0328A4D0>

My guess is you are passing a unicode string as a filename
and not an 8-bit python string.  Currently we cannot easily test
for unicode as we have to run on pre-Unicode versions of

The relevant code is in pdfdoc, class PDFDocument, method saveToFile
and does this!

 if type(filename) is StringType:
            myfile = 1
            f = open(filename, "wb")
            myfile = 0
            f = filename # IT BETTER BE A FILE-LIKE OBJECT!

So if you pass a Unicode string it assumes it's something

Solution:  either do 
   filename = str(filename)
in your code before setting up the canvas, or explicitly pass
in an open file object.


Andy Robinson