import base64 class B64Handle: def __init__(self): pass def convert_b64(self,img): with open(img,'rb') as f: base64_data=base64.b64encode(f.read()) s=base64_data.decode() return s if __name__=='__main__': hand=B64Handle() A=hand.convert_b64('WX20211229-152303.png') print(A)