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

UnicodeDecodeError on the platform name with Python 2 #97

Closed
bochecha opened this issue Apr 24, 2013 · 3 comments
Closed

UnicodeDecodeError on the platform name with Python 2 #97

bochecha opened this issue Apr 24, 2013 · 3 comments

Comments

@bochecha
Copy link

I just created a new Pyramid project on Fedora 19, with Python 2.7.4

Starting the app, I get the below traceback (last few lines because it is very long) :

Traceback (most recent call last):
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/pyramid-1.4.1-py2.7.egg/pyramid/mako_templating.py", line 207, in __call__
    result = template.render_unicode(**system)
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/template.py", line 452, in render_unicode
    as_unicode=True)
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 783, in _render
    **_kwargs_for_callable(callable_, data))
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 815, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/Mako-0.8.0-py2.7.egg/mako/runtime.py", line 841, in _exec_template
    callable_(context, *args, **kwargs)
  File "/home/bochecha/Workspace/loopapp/venv/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.6-py2.7.egg/pyramid_debugtoolbar/panels/templates/versions.dbtmako", line 2, in render_body
    <div>${platform}</div>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 152: ordinal not in range(128)

The problem is that Fedora 19 is codenamed « Schrödinger’s Cat ».

Python 2.7 sees that as:

$ python
Python 2.7.4 (default, Apr 22 2013, 07:21:08) 
[GCC 4.8.0 20130412 (Red Hat 4.8.0-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.9.0-0.rc7.git3.1.fc19.x86_64-x86_64-with-fedora-19-Schr\xc3\xb6dinger\xe2\x80\x99s_Cat'

And so the platform variable passed to the Mako template is a bytes string containing non-ascii chars, which causes the UnicodeDecodeError exception.

Editing pyramid_debugtoolbar/panels/versions.py to add a simple .decode('utf-8') where appropriate fixes the issue.

That might not be the proper fix though.

Finally, note that the problem is limited to Python 2, because Python 3 returns a unicode string:

$ python3
Python 3.3.1 (default, Apr 11 2013, 09:14:58) 
[GCC 4.8.0 20130322 (Red Hat 4.8.0-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.9.0-0.rc7.git3.1.fc19.x86_64-x86_64-with-fedora-19-Schrödinger’s_Cat'
@hanula
Copy link
Contributor

hanula commented Apr 25, 2013

Should be fixed in #98.

@sontek
Copy link
Member

sontek commented Jul 5, 2013

@bochecha Can you test with latest master and let us know if you are still seeing the issue?

@bochecha
Copy link
Author

bochecha commented Jul 6, 2013

This is indeed fixed in latest master.

Thanks! :)

@mcdonc mcdonc closed this as completed Aug 10, 2013
bochecha pushed a commit to network-box/uptrack that referenced this issue Jan 23, 2014
It causes issues on some systems (e.g Fedora 19):
    Pylons/pyramid_debugtoolbar#97

And it has limited value anyway, so let's avoid the trouble to all
people trying to setup a development instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants