[ZPT] Re: Fix for UnicodeError: ASCII decoding error: ordinal not in range(128)

Florent Guillaume fg@nuxeo.com
24 Jan 2003 19:03:18 +0100


That's probably when it tries to map the Unicode error char, u'\ufffd',
to your codepage. the error char comes from the 'replace' in the code I
propose. Try to use 'ignore' instead of 'replace' there.
Or you could also try to replace:
                    ul.append(unicode(s, defaultencoding, 'replace'))
with:
                    try:
                        ul.append(unicode(s))
                    except UnicodeError:
                        ul.append("?(unknown encoding for %s)?" % `s`)
to have something more explicit.

Florent

On Fri, 2003-01-24 at 18:55, Vladimir Iliev wrote:
> i've never seen such error before, am i wrong ? :)
> 
> Unhandled exception in thread:
> Traceback (most recent call last):
>   File "/www/Zope-2.6.1b1-src/ZServer/PubCore/ZServerPublisher.py", line
> 23, in __init__
>     response=response)
>   File "/www/Zope-2.6.1b1-src/lib/python/ZPublisher/Publish.py", line
> 160, in publish_module
>     request.response.exception()
>   File "/www/Zope-2.6.1b1-src/lib/python/ZPublisher/HTTPResponse.py",
> line 739, in exception
>     body = self.setBody(b, is_error=1)
>   File "/www/Zope-2.6.1b1-src/lib/python/ZPublisher/HTTPResponse.py",
> line 286, in setBody
>     body = self._encode_unicode(body)
>   File "/www/Zope-2.6.1b1-src/lib/python/ZPublisher/HTTPResponse.py",
> line 421, in _encode_unicode
>     return body.encode(encoding)
>   File
> "/var/tmp/python2.1-2.1.3-root/usr/lib/python2.1/encodings/cp1251.py",
> line 18, in encode
> UnicodeError: charmap encoding error: character maps to <undefined>
> 
> 
> On Fri, 2003-01-24 at 19:00, Florent Guillaume wrote:
> > But at least it's not in TranslationService anymore :-)
> > Really, I think we should have a specialized getvalue() in
> > TALInterpreter. Something along the lines of this test:
> > 
> > 
> > from StringIO import StringIO
> > from types import UnicodeType
> > import sys
> > 
> > defaultencoding = sys.getdefaultencoding()
> > 
> > class FasterStringIO(StringIO):
> >     # ...
> >     def getvalue(self):
> >         try:
> >             return ''.join(self.buflist)
> >         except UnicodeError:
> >             ul = []
> >             for s in self.buflist:
> >                 if isinstance(s, UnicodeType):
> >                     ul.append(s)
> >                 else:
> >                     ul.append(unicode(s, defaultencoding, 'replace'))
> >             return ''.join(ul)
> > 
> > a = FasterStringIO()
> > a.write('é')
> > a.write(u'é')
> > print `a.getvalue()`
> > 
> > 
> > Could you try adding that method and the necessary import into
> > TALInterpreter.py to diagnose the problem?
> > 
> > Florent
> > 
> > 
> > On Fri, 2003-01-24 at 17:42, vlado wrote:
> > > Hi,
> > > 
> > > I tryed LOCALIZER_USE_ZOPE_UNICODE=1 and hitted the same UnicodeError
> > > again.
> > > I'm using z2.6.1b1, Localizer1.0, TranslationService0.2 
> > > this is the traceback:
> > > 
> > >     *  Module ZPublisher.Publish, line 150, in publish_module
> > >     * Module Products.Localizer, line 55, in new_publish
> > >     * Module ZPublisher.Publish, line 114, in publish
> > >     * Module Zope.App.startup, line 182, in zpublisher_exception_hook
> > >     * Module ZPublisher.Publish, line 98, in publish
> > >     * Module ZPublisher.mapply, line 88, in mapply
> > >     * Module ZPublisher.Publish, line 39, in call_object
> > >     * Module Shared.DC.Scripts.Bindings, line 252, in __call__
> > >     * Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec
> > >     * Module Products.CMFCore.FSPageTemplate, line 189, in _exec
> > >     * Module Products.CMFCore.FSPageTemplate, line 122, in pt_render
> > >     * Module Products.PageTemplates.PageTemplate, line 95, in pt_render
> > >       <FSPageTemplate at /Sites/test/login_form used for /Sites/test>
> > >     * Module TAL.TALInterpreter, line 186, in __call__
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 689, in do_useMacro
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 622, in do_loop_tal
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 400, in do_optTag_tal
> > >     * Module TAL.TALInterpreter, line 385, in do_optTag
> > >     * Module TAL.TALInterpreter, line 380, in no_tag
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 655, in do_condition
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 400, in do_optTag_tal
> > >     * Module TAL.TALInterpreter, line 385, in do_optTag
> > >     * Module TAL.TALInterpreter, line 380, in no_tag
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 689, in do_useMacro
> > >     * Module TAL.TALInterpreter, line 230, in interpret
> > >     * Module TAL.TALInterpreter, line 745, in do_onError_tal
> > >     * Module StringIO, line 160, in getvalue
> > > 
> > > UnicodeError: ASCII decoding error: ordinal not in range(128) (Also, an
> > > error occurred while attempting to render the standard error message.)
> > 
> > -- 
> > Florent Guillaume, Nuxeo (Paris, France)
> > +33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com
> > 
-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com