> I have got a traceback in Pylons app. The strange thing is it is
> not displayed as other tracebacks in a pretty way, just ugly plain
> text http response. And the traceback itself gives little clue
> about what actually happened.
>
> I am using Pylons 0.9.5 + Mako.
Did this happen after you upgraded? If so, you might try clearing
your cache directory as an old Mako template might need to be
recompiled.
HTH,
Ben
I've got such error instead of SyntaxException in non-ascii Mako templates.
You may reproduce this traceback with attached test project. Check that
URIs:
http://localhost:5000/test_mako/ascii
http://localhost:5000/test_mako/unicode
http://localhost:5000/test_mako/ascii_w_error <-- SyntaxException
http://localhost:5000/test_mako/unicode_w_error <-- UnicodeDecodeError instead of SyntaxException
> On 13:40:37 Sat 14 Apr , Max Ischenko wrote:
>> Hi,
>>
>> I have got a traceback in Pylons app. The strange thing is it is not
>> displayed as other tracebacks in a pretty way, just ugly plain
>> text http
>> response. And the traceback itself gives little clue about what
>> actually
>> happened.
>>
>> I am using Pylons 0.9.5 + Mako.
>>
>> File "/usr/lib/python2.4/site-packages/Mako-0.1.5-py2.4.egg/mako/
>> runtime.py",
>> line 303, in _render_context
>> _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
>> File "/usr/lib/python2.4/site-packages/Mako-0.1.5-py2.4.egg/mako/
>> runtime.py",
>> line 336, in _exec_template
>> callable_(context, *args, **kwargs)
>> File "memory:-0x4ea1cd14", line 61, in render_body
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in
>> position 41:
>> ordinal not in range(128)
>>
>
> I've got such error instead of SyntaxException in non-ascii Mako
> templates.
>
If you're including non-ascii text inside of a Mako template, make
sure you specify a magic encoding comment at the top of the file:
http://www.makotemplates.org/docs/documentation.html#unicode_specifying
Like you would with a .py file.
--
Philip Jenvey
magic encoding is necessary, but also the stack trace above is
occuring within the render() step, so ensure that any expressions ${}
etc. which include non-ascii characters evaluate to a unicode value.
On Apr 15, 12:30 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
> > If you're including non-ascii text inside of a Mako template, make
> > sure you specify a magic encoding comment at the top of the file:
>
> >http://www.makotemplates.org/docs/
> > documentation.html#unicode_specifying
>
> > Like you would with a .py file.
>
> magic encoding is necessary, but also the stack trace above is
> occuring within the render() step, so ensure that any expressions ${}
> etc. which include non-ascii characters evaluate to a unicode value.
Sorry for not providing every detail up-front. The problem was caused
by a syntax error which caused Mako to fail when it tried to report
it.
Here is a minimal test case:
----- offending file -----
# -*- coding: utf-8 -*-
% if 2 == 2: # an innocently-looking comment
${u'привет'}
% endif
----------------------------------
If you replace unicode string with something ascii-safe you do get a
proper error from mako (CompileException).
Max.
Ah, ok. We had to fix this for Myghty 1.1, I've logged a ticket with
a patch to half-fix this:
http://www.makotemplates.org/trac/ticket/37
Mike, is there any reason why Templates don't have an
'encoding_errors' var to go along with 'output_encoding'? See that
ticket for why it might be nice to have
--
Philip Jenvey