2
Vote

Encoding Problems (Unable to translate bytes...)

description

Hi,

I'm working with a combination of IronPython and jinja2 but keep getting encoding problems from time to time when outputting special characters like 'ä' or returning such from python methods into jinja context.

For example the template:
{%- set test= 'ä' %}
{{ test }}

Can produce exceptions (System.Text.DecoderFallbackException) with the message 'Unable to translate bytes [E4] at index 0 from specified code page to Unicode.'

Adding a space character to the end of the second line can bypass this in some cases but this approach can't be used in larger templaes with a structure that changes depending on inputted data.

I guess that these errors stem from the IronPython part because the error messages are C#-Error messages.

Has someone any ideas about this or can give me a hint what I am doing wrong?

comments

Storminator16 wrote Oct 12, 2012 at 3:55 AM

http://ironpython.codeplex.com/workitem/29505

Related, and it's a old issue. As Jeff Hardy pointed out, replace to_string = unicode with to_string = lambda x: unicode(x) near line 28 of runtime.py in jinja2.