I am trying to save data received from API in file in json format.
response = requests.get(url_league, headers= header)
type(response)
#output requests.models.Response
with open("json.txt", "w+") as f:
data = json.dump(response, f)
When i trying to save response object to file i got the following error
Object of type Response is not JSON serializable
I read that json module have problems with encoding complex objects and for this purposes in json have default function to encode complex objects. I tried the following code
json_data = json.dump(response.__dict__, f, default = lambda o: o.__dict__, indent=4)
And got the following error
bytes' object has no attribute '__dict__'
What this error mean and how to solve it?
response.json()?