Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exceptions.html_error_template render fail in python3 #293

hilarryxu opened this issue Apr 30, 2019 · 4 comments

exceptions.html_error_template render fail in python3 #293

hilarryxu opened this issue Apr 30, 2019 · 4 comments


Copy link

@hilarryxu hilarryxu commented Apr 30, 2019

When use exceptions.html_error_template in python3, got:

    File "python3.7/site-packages/mako/", line 899, in _exec_template
        callable_(context, *args, **kwargs)
    File "memory:0x7efcac2aa908", line 49, in render_body
    TypeError: a bytes-like object is required, not 'str'

caused by

    tback = RichTraceback(error=error, traceback=traceback)
    src = tback.source
    line = tback.lineno
    if src:
        lines = src.split('\n')

here tback.source is bytes in python3, so src.split raise TypeError

Copy link

@zzzeek zzzeek commented Apr 30, 2019

hi there -

can you please provide a complete MCVE test case? I'm not able to reproduce, although Im not sure it's working correctly nonetheless:

from mako.template import Template
from mako import exceptions

    t = Template("<% print(x) %>")

I get back HTML source as bytes. however if I call render_unicode(), I get good HTML. No stack trace in either case. Using Python 3.7.0.

@zzzeek zzzeek added the bug label Apr 30, 2019
Copy link

@hilarryxu hilarryxu commented May 6, 2019

Like this when use TemplateLookup

from mako.lookup import TemplateLookup
from mako.exceptions import MakoException, html_error_template

    template_lookup = TemplateLookup()
    tpl = template_lookup.get_template('not_found.html')
except MakoException:

Using Python 3.7.1 Mako 1.0.9

Copy link

@sqla-tester sqla-tester commented May 10, 2019

Mike Bayer has proposed a fix for this issue in the master branch:

Use utf-8 encoding for traceback source with no encoding in py3k

Copy link

@hilarryxu hilarryxu commented May 10, 2019

It works, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants