Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


UnicodeDecodeError when string representation of context contains accented characters. #70

benwah opened this Issue · 2 comments

2 participants


So I have a simple view that returns a MongoDB dataset:

def region_selector(request):
    return {
        'regions': Region.objects.all()

But since I added a unicode method to my Region model, pyramid_debugtoolbar breaks. Here's the stack:

Traceback (most recent call last):
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/pyramid/", line 181, in __call__
    result = template.render_unicode(**system)
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/Mako-0.7.0-py2.7.egg/mako/", line 406, in render_unicode
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/Mako-0.7.0-py2.7.egg/mako/", line 764, in _render
    **_kwargs_for_callable(callable_, data))
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/Mako-0.7.0-py2.7.egg/mako/", line 796, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/Mako-0.7.0-py2.7.egg/mako/", line 822, in _exec_template
    callable_(context, *args, **kwargs)
  File "/sites/envs/tuktu/local/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.2-py2.7.egg/pyramid_debugtoolbar/panels/templates/renderings.dbtmako", line 21, in render_body
    <td colspan="2">${rendering['val']|h}</td>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 30: ordinal not in range(128)

I enabled pdb in, in function content, maybe it will help:

> /sites/envs/tuktu/local/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.2-py2.7.egg/pyramid_debugtoolbar/panels/
-> return self.render(
(Pdb) print self.renderings[0]['val']
{'regions': [<Region: Saguenay–Lac-Saint-Jean>, <Region: Gaspésie–Îles-de-la-Madeleine>, <Region: Lanaudière>, <Region: Chaudière-Appalaches>, <Region: Montréal>, <Region: Nord-du-Québec>, <Region: Mauricie>, <Region: Côte-Nord>, <Region: Montérégie>, <Region: Bas-Saint-Laurent>, <Region: Abitibi-Témiscamingue>, <Region: Centre-du-Québec>, <Region: Laurentides>, <Region: Laval>, <Region: Outaouais>, <Region: Estrie>, <Region: Saint-Pierre et Miquelon>, <Region: t2>, <Region: t1>]}

Note that the data type above is str.


Ok I found a fix.. I don't think it's a perfect fix though, am afraid it only works for utf8 data :P

in pyramid_debugtoolbar/panels/, here's the diff:

<         self.renderings.append(dict(name=name, system=dictrepr(event), val=val))
>         self.renderings.append(dict(name=name, system=dictrepr(event), val=val.decode('utf8')))

same happens to me, making whole pyramid development server returning Internal Server Error.

If I return objects, which repr returns a string with utf8 encoded non-ascii characters (eg. ł), but almost works, when repr is unicode.
Almost, becouse I get for Rendering Value in Rendering section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.