Wie man Text zu base64 in Python kodiert
Bin ich versucht zu codieren, einen text-string in base64.
habe ich versucht, dies zu tun :
name = "your name"
print('encoding %s in base64 yields = %s\n'%(name,name.encode('base64','strict')))
Aber das gibt mir die folgende Fehlermeldung:
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs
Wie gehe ich über das tun dies ? ( mit Python 3.4)
InformationsquelleAutor der Frage sukhvir | 2014-04-18
Du musst angemeldet sein, um einen Kommentar abzugeben.
Erinnern, import base64 und b64encode dauert bytes als argument.
InformationsquelleAutor der Antwort Alex Hristov
1) Das funktioniert ohne Importe in Python 2:
(obwohl dies funktioniert nicht Python ist3 )
2) In Python 3 müssten Sie den import base64 und tun base64.b64decode('...')
- funktioniert auch in Python 2 zu.
InformationsquelleAutor der Antwort Tagar
Es stellt sich heraus, dass dies wichtig genug, um es ist ein eigenes Modul...
InformationsquelleAutor der Antwort mgilson
Kompatibilität mit sowohl py2 und py3
InformationsquelleAutor der Antwort Five
Verwenden Sie den folgenden code:
InformationsquelleAutor der Antwort ujjawal sharma