python - django bytesIO to base64 String & return as JSON -
i using python 3 & have code, trying base64 out of stream , returnn json - not working.
       stream = bytesio()        img.save(stream,format='png')        return base64.b64encode(stream.getvalue())   in view, have:
hm =mymap()     strhm = hm.generate(data) return httpresponse(json.dumps({"img": strhm}),content_type="application/json"  )   getting error not json serializable. base64.b64encode(stream.getvalue()) seems giving bytes
in python 3.x, base64.b64encode accepts bytes object , returns bytes object.
>>> base64.b64encode(b'a') b'yq==' >>> base64.b64encode(b'a').decode() 'yq=='   you need convert str object, using bytes.decode:
return base64.b64encode(stream.getvalue()).decode()      
Python - Django Bytesio To Base64 String And Return As Json - >>>>> Download Now
ReplyDelete>>>>> Download Full
Python - Django Bytesio To Base64 String And Return As Json - >>>>> Download LINK
>>>>> Download Now
Python - Django Bytesio To Base64 String And Return As Json - >>>>> Download Full
>>>>> Download LINK I3