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

Flask Debug Toolbar Does Not Check For A Compressed Response #83

Closed
JackStouffer opened this issue Jun 19, 2015 · 5 comments
Closed

Flask Debug Toolbar Does Not Check For A Compressed Response #83

JackStouffer opened this issue Jun 19, 2015 · 5 comments

Comments

@JackStouffer
Copy link

If you have an extension like Flask Compress compressing the contents of your responses with gzip before it's sent back to the user, flask debug toolbar will throw an error because it assumes the response is UTF-8 HTML.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/site-packages/flask_restful/__init__.py", line 270, in error_router
    return original_handler(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
    response = self.process_response(response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1691, in process_response
    response = handler(response)
  File "/usr/local/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 202, in process_response
    response_html = response.data.decode(response.charset)
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: invalid start byte
@mgood
Copy link
Contributor

mgood commented Jun 19, 2015

Can you try flipping the order that you add the extensions to your app? This should make the compression step happen after applying the toolbar.

@ffoxin
Copy link

ffoxin commented Oct 19, 2015

Same problem with either Flask-Compress and manual gzip (recipe from http://flask.pocoo.org/snippets/122/). How can I reorder applying it?

@mgood
Copy link
Contributor

mgood commented Oct 20, 2015

Swapping the lines of code where you add the toolbar and add the compress extension should swap the order that they're executed. I think the "after_request" functions are processed in reverse order, so Flask-Compress should be the first extension initialized so that it's the last one called.

@jeffwidman
Copy link
Member

jeffwidman commented Jul 6, 2016

Actually, I think the we could throw a more useful error message here... suggest to the user that if they're compressing to swap extension ordering.

@jeffwidman
Copy link
Member

Fixed in #154.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants