"LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs In Python
Dung Do Tien Jun 06 2021 845
I'm a newbie in Python and now I want to encode a text string to base64. I have some line code below:
phone = "0234566778" name ="Jonh" print('%s is trying encode his phone in base64 = %s\n'%(name,phone.encode('base64','strict')))
When running this code I got an error:
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs
How can I resolve it?
Have 2 answer(s) found.
jrobertojrmx Jose Roberto Jun 06 2021
You can try a simple way below:
import base64 base64.b64encode('Your string text here'.encode('ascii'))
And it works for me.
Mai Nguyen Nhat Dang Jun 06 2021
You need to import
base64package. It helps convert encode text string to base 64. See example:
import base64 base64.b64encode(bytes('your tex string here', 'utf-8'))
I hope it works for you.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.