I totally new in Python and stuck with this error:
I am trying to encode an image and then convert it to json to upload into a no-sql db. But when I am trying to convert it to json I am getting this error:
"AttributeError: 'bytes' object has no attribute 'dict'"
Below is my python code:
import base64
import json
def jsonDefault(object):
return object.__dict__
with open("img123.png", "rb") as imageFile:
str = base64.b64encode(imageFile.read())
print(str)
json_str = {'file_name':'img123','img_str':str}
pytojson = json.dumps(json_str, default=jsonDefault)
print(pytojson)