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

Closed
hilarryxu opened this issue Apr 30, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@hilarryxu
Copy link

commented Apr 30, 2019

When use exceptions.html_error_template in python3, got:

    File "python3.7/site-packages/mako/runtime.py", 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

@zzzeek

This comment has been minimized.

Copy link
Member

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

try:
    t = Template("<% print(x) %>")
    print(t.render())
except:
    print(exceptions.html_error_template().render())

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

@hilarryxu

This comment has been minimized.

Copy link
Author

commented May 6, 2019

Like this when use TemplateLookup

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

try:
    template_lookup = TemplateLookup()
    tpl = template_lookup.get_template('not_found.html')
    tpl.render()
except MakoException:
    print(html_error_template().render())

Using Python 3.7.1 Mako 1.0.9

@sqla-tester

This comment has been minimized.

Copy link
Collaborator

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 https://gerrit.sqlalchemy.org/1261

@hilarryxu

This comment has been minimized.

Copy link
Author

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
You can’t perform that action at this time.