How to encode text to base64 in python

前端 未结 8 2191
悲&欢浪女
悲&欢浪女 2020-12-24 01:17

I am trying to encode a text string to base64.

i tried doing this :

name = \"your name\"
print(\'encoding %s in base64 yields = %s\\n\'%(name,name.en         


        
8条回答
  •  长情又很酷
    2020-12-24 01:23

    It turns out that this is important enough to get it's own module...

    import base64
    base64.b64encode(b'your name')  # b'eW91ciBuYW1l'
    base64.b64encode('your name'.encode('ascii'))  # b'eW91ciBuYW1l'
    

提交回复
热议问题