当转换为 base64 时,出现 TypeError: 'str' 不支持缓冲区接口。

5
im = Image.open(filePath)                     # load image
self.msg = str(bytearray(list(im.getdata()))) # convert image data to string
encodedMsg = base64.b64encode(self.msg)

当我尝试将从图像中读取的数据编码为base64时,出现了错误:
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)时,它可以正常工作。但当我在学校机器上使用Python 3.4时,它会显示错误信息。我该如何解决这个问题?

2个回答

10

0

我从xml文件中读取了一些数据。这段代码self.msg = base64.b64decode(self.xml.encode('utf-8'))返回了File "/opt/python3/current/lib/python3.4/base64.py", line 90, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding - BadEggX

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接