Alternatively, enable implicit decoding using ``default_encoding="utf-8"`` (in the template constructor). This is enabled on Plone, for instance.
\malthe On 16 December 2010 14:47, Tres Seaver <tsea...@palladion.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 12/15/2010 10:18 PM, Iain Duncan wrote: >> Not sure where I'm supposed to ask this now, here? Pyramid list? >> >> I have view with a chameleon template that contains utf-8 unicode special >> chars. It renders fine when rendered on it's own from a view. As soon as I >> wrap that view with a wrapper view, I get errors with the wrapper choking on >> the unicode. >> >> My master views call method is like this: >> >> def __call__(self): >> tmpl_dict = {} >> tmpl_dict['inner_content'] = self.request.wrapped_body >> return tmpl_dict >> >> >> I get the following traceback ( snipped ): >> File >> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/router.py", >> line 130, in __call__ >> response = view_callable(context, request) >> File >> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py", >> line 1724, in _owrapped_view >> wrapper_viewname) >> File >> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/view.py", >> line 90, in render_view_to_response >> return view(context, request) >> File >> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py", >> line 1663, in _bfg_class_view >> response = inst() >> File "/home/jordans/Jordans/jordans/views/master_view.py", line 22, in >> __call__ >> tmpl_dict['inner_content'] = u"%s" % self.request.wrapped_body >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4090: >> ordinal not in range(128) >> >> >> Any clues? > > The code in the traceback doesn't match the sample you showed above: > the 'wrapped_body' is an encoded string (WebOb responses always encode > the body with the supplied charset) which the view is trying to decode > (back?) to unicode without supplying the encoding. The default encoding > used by WebOb is 'UTF-8', so I would try: > > def __call__(self): > tmpl_dict = {} > body = self.request.wrapped_body > tmpl_dict['inner_content'] = body.decode('UTF-8') > return tmpl_dict > > > > Tres. > - -- > =================================================================== > Tres Seaver +1 540-429-0999 tsea...@palladion.com > Palladion Software "Excellence by Design" http://palladion.com > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAk0KGHEACgkQ+gerLs4ltQ7FZQCgzIl5cIsJbt1viMO8KKAre97j > ne8An1T4tFdxXHTQzOcSJyWpP7hGiBcq > =Ty1s > -----END PGP SIGNATURE----- > _______________________________________________ > Repoze-dev mailing list > Repoze-dev@lists.repoze.org > http://lists.repoze.org/listinfo/repoze-dev > _______________________________________________ Repoze-dev mailing list Repoze-dev@lists.repoze.org http://lists.repoze.org/listinfo/repoze-dev