Object of type 'bytes' is not JSON serializable in python3

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 07:12:36

问题


My Code is

configfile = open("abc.txt",'rb').read()
return base64.b64encode(configfile)

got error "Object of type 'bytes' is not JSON serializable in python3.6" on ec2


回答1:


Above issue appeared when i updated Django 1.8 to Django 2.2.6

I solve this by

Consider installing and using [simplejson][1], which can handle bytes strings in addition to unicode, to install it use command below:

pip3 install simplejson

Usage in code:

import simplejson as json

json.dumps({b'name': b'dev'})

This will solve JSON serializable issue.



来源:https://stackoverflow.com/questions/58452367/object-of-type-bytes-is-not-json-serializable-in-python3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!