makoを使用すると、このエラーが常に発生します。
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 6: ordinal not in range(128)
私はmakoに可能な限りユニコードを使用していると言いました:
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)
私のすべてのテンプレートファイルは次で始まります:
## -*- coding: utf-8 -*-
そして、それらの内部では、すべてのコストのかかる文字列の前に「u」が付いています。self.stuffパラメーターにUnicode文字列が含まれていることは知っていますが、makoオブジェクトをインスタンス化する方法でそれを処理する必要があります(そうでない場合、これらの引数は何に適していますか?)。忘れたことはありますか?
もう1つの質問:encoding_errors ='replace'のポイントは何ですか?
= EDIT =ユニコード文字列を1つだけ残しました。これは、トレースバックです。
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 <lambda>
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)