转换为base 64时,TypeError:'str'不支持缓冲区接口 [英] when convert to base 64, TypeError: 'str' does not support the buffer interface
本文介绍了转换为base 64时,TypeError:'str'不支持缓冲区接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
im = Image.open(filePath) # load image
self.msg = str(bytearray(list(im.getdata()))) # convert image data to string
encodedMsg = base64.b64encode(self.msg)
当我尝试将从图像读取的数据编码为base64时,它返回错误:
when I was trying to encode the data read from an image to base64, it returns an error:
File "Steganography.py", line 42, in msgToXml
encodedMsg = base64.b64encode(self.msg)
File "/opt/python3/current/lib/python3.4/base64.py", line 62, in b64encode
encoded = binascii.b2a_base64(s)[:-1]
TypeError: 'str' does not support the buffer interface
当我在家使用Ubuntu(python 2.7)时,它可以工作.但是当我使用学校机器(python3.4)时,它显示错误.我该如何解决?
It works when I'm home using Ubuntu(python 2.7). But it shows error when I use school machine(python3.4). How can I solve this?
推荐答案
encodedMsg = base64.b64encode(self.msg.encode('ascii'))
这篇关于转换为base 64时,TypeError:'str'不支持缓冲区接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文