'How to attach a gz file to a json object in python?

I have an api that returns a gz file. The application from where I am running the api accepts only json formats. Is there a way to attach the returned gz file to a json object? Would converting the gz file to base64 format and then creating a json object like { "file": "the base64 format" } work?

print(json.dumps({'file': base64.b64decode(response_alert.content)}))

I get the error

Object of type bytes is not JSON serializable


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source