Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when convert to base 64, TypeError: 'str' does not support the buffer interface [duplicate]

Tags:

python

base64

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

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

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?

like image 359
BadEggX Avatar asked Nov 26 '14 23:11

BadEggX


1 Answers

encodedMsg = base64.b64encode(self.msg.encode('ascii'))

reference: Base64 encoding in Python 3

like image 75
BadEggX Avatar answered Nov 14 '22 22:11

BadEggX