How to encode integer in to base64 string in python 3 -
this question has answer here:
- base64 encoding in python 3 5 answers
i'm trying encode int in base64, i'm doing that:
foo = 1 base64.b64encode(bytes(foo)) expected output: 'mq=='
given output: b'aa=='
what i'm doing wrong?
edit: in python 2.7.2 works correctly
thanks!
try this:
foo = 1 base64.b64encode(bytes([foo])) or
foo = 1 base64.b64encode(bytes(str(foo), 'ascii')) # or, equivalently: base64.b64encode(str(foo).encode('ascii')) the first example encodes 1-byte integer 1. 2nd example encodes 1-byte character string '1'.
Comments
Post a Comment