python 3.5
代码如下:
# 二进制方式打开图文件
f = open('face/xxx.jpg', 'rb')
# 参数images:图像base64编码
img = base64.b64encode(f.read())
#解码转成字符串
img_string = img.decode('utf-8')
#json
dict_img = {'image':img_string}
result = json.dumps(dict_img)
print(result)
打印:
ILhofl53eWPUD/PWpcWtQckjzq5g..........
错了。
img
已经是“字节”了。还有,base64 是“编码”,不是“加密”。