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 when handling certain row values #49

Open
ghost opened this issue Jan 17, 2014 · 2 comments
Open

UnicodeDecodeError when handling certain row values #49

ghost opened this issue Jan 17, 2014 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 17, 2014

When clicking on the table name in the admin header:

Traceback:

Traceback (most recent call last):
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/base.py", line 60, in inner
    return f(self, *args, **kwargs)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/base.py", line 60, in inner
    return f(self, *args, **kwargs)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/model/base.py", line 1182, in index_view
    actions_confirmation=actions_confirmation)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/base.py", line 254, in render
    return render_template(template, **kwargs)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template
    context, ctx.app)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask/templating.py", line 110, in _render
    rv = template.render(context)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/model/list.html", line 4, in top-level template code
    {% import 'admin/actions.html' as actionlib with context %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/master.html", line 1, in top-level template code
    {% extends admin_base_template %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/base.html", line 22, in top-level template code
    {% block page_body %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/base.html", line 50, in block "page_body"
    {% block body %}{% endblock %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/model/list.html", line 49, in block "body"
    {% block model_list_table %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/model/list.html", line 95, in block "model_list_table"
    {% block list_row scoped %}
  File "/Users/jan/.virtualenvs/foo/lib/python2.7/site-packages/flask_admin/templates/admin/model/list.html", line 118, in block "list_row"
    <td>{{ get_value(row, c) }}</td>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position 2: ordinal not in range(128)

Having a look at the value using the Werkzeug debugger:

c
u'chatmsg_guid'
row.chatmsg_guid
'Qc\x8f0;\xd3\xb9\xac\xd8\xc8\x11S\xc4\xb5\xed9"Q\xf21\x19#\x9a\xd0@[\xa2zH\xe4Y\xe4'

So, it's really a binary value that's not to be decoded in this case. Maybe just catch the exception and spit back the string's repr() if it can't be decoded?

@jeffknupp
Copy link
Owner

Hmm. What is the column type of the binary data? If it's using a proper column rather than something like VARCHAR, I could probably add a fix for this. Either way, I'm working on an easy way that you could prevent that column from being displayed.

@annchies
Copy link

@jeffknupp Is there a way to hide the column who's data type is binary, because I get UnicodeDecodeError when I go to the admin page?

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

2 participants