Home > Software design >  Using Flask make_response with gzip not returning content
Using Flask make_response with gzip not returning content

Time:07-07

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?

CodePudding user response:

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

  • Related