How to encode text to base64 in python

前端 未结 8 2158
悲&欢浪女
悲&欢浪女 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

    To compatibility with both py2 and py3

    import six
    import base64
    
    def b64encode(source):
        if six.PY3:
            source = source.encode('utf-8')
        content = base64.b64encode(source).decode('utf-8')
    

提交回复
热议问题