Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Flask make_response with gzip not returning content

I am trying to use gzip to compress a very large dictionary and send it through Flask.

content = gzip.compress(json.dumps(large_dict).encode('utf8'), 9)

# this prints a bytes object like b'\x1f\x8b\x08\x00b\x14\xc6b ... '
print(content)

response = make_response(content)
response.headers['Content-length'] = len(content)
response.headers['Content-Encoding'] = 'gzip'

# these print: 'Response' object has no attribute 'content/text'
print(response.content)
print(response.text)

# this prints: 'NoneType' object is not callable
print(response.json())

How do I get the bytes object from the response so that I can use gzip to decompress?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you look at the Response page, it seems like you are looking for get_data or just the attribute data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading