what is the best way to save PIL image in json
问题 I'm trying to send json dict that should contain Pillow image as one of his fields, to do that I have to convert the image to string. I tried to use pillow function: image.toString() but still got it as bytes, so I tried to encode it: buff = BytesIO() image.save(buff, format="JPEG") img_str = base64.b64encode(buff.getvalue()) but still got it as bytes. How can I convert Pillow images to format that can be saved in json file? 回答1: In the comments, Mark Setchell suggests calling .decode('ascii'