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

Vladimir Iliev vlado@vintech.bg
24 Jan 2003 19:55:02 +0200


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=3Dresponse)
  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 =3D self.setBody(b, is_error=3D1)
  File "/www/Zope-2.6.1b1-src/lib/python/ZPublisher/HTTPResponse.py",
line 286, in setBody
    body =3D 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:
>=20
>=20
> from StringIO import StringIO
> from types import UnicodeType
> import sys
>=20
> defaultencoding =3D sys.getdefaultencoding()
>=20
> class FasterStringIO(StringIO):
>     # ...
>     def getvalue(self):
>         try:
>             return ''.join(self.buflist)
>         except UnicodeError:
>             ul =3D []
>             for s in self.buflist:
>                 if isinstance(s, UnicodeType):
>                     ul.append(s)
>                 else:
>                     ul.append(unicode(s, defaultencoding, 'replace'))
>             return ''.join(ul)
>=20
> a =3D FasterStringIO()
> a.write('=C3=A9')
> a.write(u'=C3=A9')
> print `a.getvalue()`
>=20
>=20
> Could you try adding that method and the necessary import into
> TALInterpreter.py to diagnose the problem?
>=20
> Florent
>=20
>=20
> On Fri, 2003-01-24 at 17:42, vlado wrote:
> > Hi,
> >=20
> > I tryed LOCALIZER_USE_ZOPE_UNICODE=3D1 and hitted the same UnicodeError
> > again.
> > I'm using z2.6.1b1, Localizer1.0, TranslationService0.2=20
> > this is the traceback:
> >=20
> >     *  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
> >=20
> > UnicodeError: ASCII decoding error: ordinal not in range(128) (Also, an
> > error occurred while attempting to render the standard error message.)
>=20
> --=20
> Florent Guillaume, Nuxeo (Paris, France)
> +33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com
>=20
--=20
Vladimir Iliev
http://www.vintech.bg