Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to deal with unicode in mako?
    primarykey
    data
    text
    <p>I constantly get this error using mako:</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 6: ordinal not in range(128) </code></pre> <p>I've told mako I'm using unicode in any possible way:</p> <pre><code> mylookup = TemplateLookup( directories=['plugins/stl/templates'], input_encoding='utf-8', output_encoding='utf-8', default_filters=['decode.utf8'], encoding_errors='replace') self.template = Template(self.getTemplate(), lookup=mylookup, module_directory=tempfile.gettempdir(), input_encoding='utf-8', output_encoding='utf-8', default_filters=['decode.utf8'], encoding_errors='replace') html = self.template.render_unicode(data=self.stuff) </code></pre> <p>All my template files starts with:</p> <pre><code>## -*- coding: utf-8 -*- </code></pre> <p>and, inside them, all costant strings are prefixed with "u". I know the self.stuff parameter contains unicode strings, but the way I instantiate the mako objects should take care of it (otherwise what those arguments are good for?). Is there anything I forgot to do?</p> <p>One more question: what's the point of encoding_errors='replace'?</p> <p>=EDIT= I left only a single unicode string and this is the traceback:</p> <pre><code>Traceback (most recent call last): File "C:\My Dropbox\src\flucso\src\plugins\stl\main.py", line 240, in updateView flags=self.makoflags) File "C:\Python26\lib\site-packages\mako-0.3.4-py2.6.egg\mako\template.py", line 198, in render_unicode as_unicode=True) File "C:\Python26\lib\site-packages\mako-0.3.4-py2.6.egg\mako\runtime.py", line 403, in _render _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data)) File "C:\Python26\lib\site-packages\mako-0.3.4-py2.6.egg\mako\runtime.py", line 434, in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File "C:\Python26\lib\site-packages\mako-0.3.4-py2.6.egg\mako\runtime.py", line 457, in _exec_template callable_(context, *args, **kwargs) File "memory:0x41317f0", line 89, in render_body File "C:\Python26\lib\site-packages\mako-0.3.4-py2.6.egg\mako\runtime.py", line 278, in &lt;lambda&gt; return lambda *args, **kwargs:callable_(self.context, *args, **kwargs) File "FriendFeed_mako", line 49, in render_inlist_entry File "C:\Python26\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeEncodeError: 'ascii' codec can't encode character u'\u263c' in position 8: ordinal not in range(128) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload