ralfonso / theory

Python web based MPD client with a pretty face and some ajax where it makes sense
http://theory.steelbreeze.org/
MIT License
34 stars 12 forks source link

UnicodeDecodeError at non-ascii album names #5

Open janLo opened 13 years ago

janLo commented 13 years ago

The exception is raised in Playlist rendering. The problem-album-entry ist the folowing: {'album': 'Boh\xc3\xa8me', 'artist': 'Annett Louisan', 'date': '2004', 'file': 'mp3 Jan/Annett Louis ian/Annett Louisan - Boheme/(Annett Louisan - Boh\xc3\xa8me 01) - Das Spiel.mp3', 'genre': 'Easy Listening', 'id': '790', 'pos': '0', 'time': '182', 'title': 'Das Spiel', 'track': '01'}

The Traceback: File 'theory/theory/controllers/playlist.py', line 48 in index return render('/playlist.html') File 'theory/env/lib/python2.6/site-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 243 in render_mako cache_type=cache_type, cache_expire=cache_expire) File 'theory/env/lib/python2.6/site-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 218 in cached_template return render_func() File 'theory/env/lib/python2.6/site-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 240 in render_template return literal(template.render_unicode(_globs)) File 'theory/env/lib/python2.6/site-packages/Mako-0.3.6-py2.6.egg/mako/template.py', line 292 in render_unicode as_unicode=True) File 'theory/env/lib/python2.6/site-packages/Mako-0.3.6-py2.6.egg/mako/runtime.py', line 575 in _render __kwargs_forcallable(callable, data)) File 'theory/env/lib/python2.6/site-packages/Mako-0.3.6-py2.6.egg/mako/runtime.py', line 607 in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File 'theory/env/lib/python2.6/site-packages/Mako-0.3.6-py2.6.egg/mako/runtime.py', line 633 in _exectemplate callable(context, _args, *_kwargs) File 'theory/data/templates/body.html.py', line 47 in render_body M_writer(escape(self.body())) File 'theory/data/templates/playlist.html.py', line 97 in render_body M_writer(escape(t['album'].replace("'","\'"))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)

Thank you Jan

janLo commented 13 years ago

Look at https://github.com/janLo/theory/commit/71b5ab31167295712639285a68806d5a82f72e4c for a quick and dirty fix

YenTheFirst commented 13 years ago

I wrote a slightly less quick and dirty fix for this:

I opened up an issue on python-mpd here: http://jatreuman.indefero.net/p/python-mpd/issues/4/

mpd's entire protocol is utf-8 encoded, so the helper should recognize this and automatically decode, but python-mpd doesn't. (Actually, I think putting that fix in place removes the need for a lot of encode() and decode()s in the program)

However, this fix also requires a fix: python2.6's urllib.quote doesn't like Unicode strings, so I changed the onclick line in tracks.html to: onclick="addToPlaylist('${t['file']}')"

this doesn't look like it introduces any errors, though, since it's automatically escaped anyway by the framework (I think)

I could fork and put in a pull request, if you'd like