How to encode integer in to base64 string in python 3 -


this question has answer here:

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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -