UnicodeDecodeError for sql queries containing unicode #60

fillest opened this Issue Apr 1, 2012 · 4 comments


None yet
5 participants

fillest commented Apr 1, 2012

  File "/home/f/venvs/x/local/lib/python2.7/site-packages/mako/runtime.py", line 704, in _exec_template
    callable_(context, *args, **kwargs)
  File "/home/f/venvs/x/local/lib/python2.7/site-packages/pyramid_debugtoolbar/templates/toolbar.dbtmako", line 61, in render_body
  File "/home/f/venvs/x/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/sqla.py", line 103, in content
    need = self.request.exc_history.token + stmt + params
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 175: ordinal not in range(128)

Should i provide some more info?
Excerpt from query printed to terminal: tags LIKE '%%#\u0442\u0435\u0441\u0442#%%' (it's "тест" in russian)
I get input from request.POST, retrieve this value with some regexp and construct a part of query by hand i.e. u"tags LIKE '%%#%s#%%'" % match

I received this error too. It was caused when SQLAlchemy raised a NoResultFound exception during a query operation. The string that ended up in panels/sqla.py was "\t\x8fk\xcdF!\xd3s\xca\xdeN\x83&'\xb4\xf6". Haven't delved much deeper into how/why this was emitted, but the fix is quite simple and involves just catching the UnicodeDecodeError. Line 100, panels/sqla.py:
except (TypeError, UnicodeDecodeError):
This should be safe since the catch doesn't do anything special for TypeErrors either.


brodul commented Jul 8, 2013

We are fixing this issue please see: Pylons/pyramid_debugtoolbar#108

icemac commented Aug 29, 2013

Attention: #108 does not fix this problem. (Tried it after it got merged.)


mmerickel commented Aug 12, 2015

This should be fixed in #232 as we aren't using the query hash any more.

mmerickel closed this Aug 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment