strange traceback

5 views
Skip to first unread message

Max Ischenko

unread,
Apr 14, 2007, 6:40:37 AM4/14/07
to pylons-...@googlegroups.com
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.

Exception happened during processing of request from ('127.0.0.1', 40788)
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/httpserver.py", line 592, in process_request_in_thread
    self.finish_request(request, client_address)
  File "SocketServer.py", line 254, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "SocketServer.py", line 521, in __init__
    self.handle()
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/httpserver.py", line 400, in handle
    BaseHTTPRequestHandler.handle(self)
  File "BaseHTTPServer.py", line 316, in handle
    self.handle_one_request()
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/httpserver.py", line 395, in handle_one_request
    self.wsgi_execute()
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/httpserver.py", line 266, in wsgi_execute
    self.wsgi_start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/urlmap.py", line 202, in __call__
    return app(environ, start_response)
  File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/paste/deploy/config.py", line 276, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/debug/prints.py", line 97, in __call__
    status, headers, body = wsgilib.intercept_output(
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/wsgilib.py", line 539, in intercept_output
    app_iter = application(environ, replacement_start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/cascade.py", line 92, in __call__
    return self.apps[-1](environ, start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/registry.py", line 327, in __call__
    app_iter = self.application(environ, start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/recursive.py", line 80, in __call__
    return self.application(environ, start_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/errordocument.py", line 185, in __call__
    app_iter = self.application(environ, change_response)
  File "/usr/lib/python2.4/site-packages/Paste-1.3-py2.4.egg/paste/evalexception/middleware.py", line 186, in __call__
    return self.respond(environ, start_response)
  File "/usr/lib/python2.4/site-packages/Pylons-0.9.5-py2.4.egg/pylons/error.py", line 269, in respond
    return debug_info.content()
  File "/usr/lib/python2.4/site-packages/Pylons-0.9.5-py2.4.egg/pylons/error.py", line 308, in content
    result = formatter_(self.exc_value)
  File "/usr/lib/python2.4/site-packages/Pylons-0.9.5-py2.4.egg/pylons/error.py", line 288, in mako_html_data
    return mako.exceptions.html_error_template().render()[610:-16]
  File "/usr/lib/python2.4/site-packages/Mako-0.1.5-py2.4.egg/mako/template.py", line 109, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/python2.4/site-packages/Mako-0.1.5-py2.4.egg/mako/runtime.py", line 286, in _render
    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
  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)
----------------------------------------

Ben Bangert

unread,
Apr 14, 2007, 1:04:49 PM4/14/07
to pylons-...@googlegroups.com
On Apr 14, 2007, at 3:40 AM, Max Ischenko wrote:

> 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

Yury Yurevich

unread,
Apr 14, 2007, 2:25:46 PM4/14/07
to pylons-...@googlegroups.com
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.

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

empty.zip

Philip Jenvey

unread,
Apr 14, 2007, 2:31:31 PM4/14/07
to pylons-...@googlegroups.com

On Apr 14, 2007, at 11:25 AM, Yury Yurevich wrote:

> 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


Michael Bayer

unread,
Apr 14, 2007, 5:30:33 PM4/14/07
to pylons-...@googlegroups.com

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.

Max Ischenko

unread,
Apr 15, 2007, 2:55:20 AM4/15/07
to pylons-discuss
Hi,

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.

Philip Jenvey

unread,
Apr 15, 2007, 6:24:17 PM4/15/07
to pylons-...@googlegroups.com

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


Reply all
Reply to author
Forward
0 new messages