Flask-gzip icon indicating copy to clipboard operation
Flask-gzip copied to clipboard

Attempted implicit sequence conversion but the response object is in direct passthrough mode.

Open michaelfillier opened this issue 12 years ago • 7 comments

Is there a way to test this out while using Flask's built-in development server? I tried and I get an error:

"RuntimeError: Attempted implicit sequence conversion but the response object is in direct passthrough mode."

Here is the link of code on werkzeug that throws the error: https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L897

michaelfillier avatar Jul 19 '13 19:07 michaelfillier

You can set response.direct_passthrough = False manually in your after_request function. This will override your error. I had the same problem, and this is just a quick fix.

However, response.data is suggested by Flask to not be used as it is in this plugin, and that it will be deprecated at some point. The only other proper way to fix this is to build your own subclass for the Response class, or edit the current one with process_response(). You can simply override these functions and define them as you wish, giving you complete control of your responses.

JoePeacock avatar Aug 27 '13 21:08 JoePeacock

I am having this problem as well. my app doesn't use any @werkzeug classes at all, just flask and flask-gzip. perhaps someone from @werkzeug can help.

rbpasker avatar Mar 04 '14 15:03 rbpasker

Checkout https://github.com/elasticsales/Flask-gzip/pull/10, if you use his fix, it should work ok.

JoePeacock avatar Mar 04 '14 21:03 JoePeacock

+1 @JoePeacock . @anemitz @philfreo would you guys mind merging #10 and updating the pip package ( #6)

joshblum avatar Apr 10 '15 10:04 joshblum

We haven't had a chance to maintain this project in a while -- you might want to check out https://github.com/wichitacode/flask-compress in the meantime

philfreo avatar Apr 10 '15 17:04 philfreo

Great, thanks!

El viernes, 10 de abril de 2015, Phil Freo [email protected] escribió:

We haven't had a chance to maintain this project in a while -- you might want to check out https://github.com/wichitacode/flask-compress in the meantime

— Reply to this email directly or view it on GitHub https://github.com/elasticsales/Flask-gzip/issues/7#issuecomment-91635827 .

joshblum avatar Apr 10 '15 17:04 joshblum

EDIT: my mistake simply moved to be defined as the last app.after_request

Hi, I have Flask 1.0.2 I've tried

@app.after_request
def after_request(r):
    r.direct_passthrough = False
    ... other after hooks....
    return r

and it doesn't work. The code fails before even reaching there. 

ohadperry avatar Jun 17 '19 09:06 ohadperry