I have a script were I save a 64 character hexadecimal ethereum privatekey on an rfid chip:
text = input('New data:')
print("Now place your tag to write")
b64 = codecs.encode(codecs.decode(text, 'hex'), 'base64').decode()
print(b64)
reader.write(b64)
print("Written")
Which converts my privatekey into a string like this
PFed9wmiwVB9vsQtFWJfGGIY2XuLu1uyfdXNc6Sa4KU=
Now when I want to convert this back to the privatekey I run into errors with this script in python3:
import base64
text = 'PFed9wmiwVB9vsQtFWJfGGIY2XuLu1uyfdXNc6Sa4KU='
dec = base64.b64decode(text).encode('hex')
print(dec)
However decoding works fine in python2.
This is the error message:
dec = base64.b64decode(text).encode('hex')
AttributeError: 'bytes' object has no attribute 'encode'
I only get this error message in python3.