[Zope3-Users] UnicodeDecodeError

Ruslan Spivak rspivak at nuxeo.com
Mon Oct 2 04:38:42 EDT 2006


В Пнд, 02/10/2006 в 02:56 -0500, David Johnson пишет:
> Good morning,
> 
>  
> 
> I’m getting a UnicodeDecodeError during the display of a ZPT and I’m
> not sure how to get rid of it.  I know the problem is related to the
> fact that we are trying to display text that contains characters above
> the 128 range.  We are displaying information from a database and
> unfortunately our users have putting non-Unicode characters in.  We
> would be glad to just strip out the non-compliant characters, but I am
> not sure how.  Any ideas or suggestions are welcome.
> 
>  
> 
>   File "/usr/share/zope3/lib/python/zope/tal/talinterpreter.py", line
> 770, in do_insertStructure_tal
> 
>     text = unicode(structure)
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position
> 739: ordinal not in range(128)
> 
>  
> 
> Corresponding TAL code:
> 
>         <td tal:content="structure
> python:view.emailLink(email.logdate,
> 
> 
> email.emailsubject,email.emailto,email.emailfrom,email.emailbody)">
> 
>             <a>Password Sent</a>
> 

Hi.

I think you just need in your view's emailLink method return unicode
string by constructing it from encoded string. Assuming that you use
iso-8869-15 encoding (you may use something different, of course, in
your db) it will be something like:

def emailLink(...):
    s = '...'
    ...
    return unicode(s, 'iso-8859-15')


Regards,
Ruslan



More information about the Zope3-users mailing list