I'm trying to import base64 on the SEEED Xiao ESP32-C3 which is running circuitpython version 8 beta 6. However, when I use import base64 or import ubase64 I see the error ImportError: no module named 'base64' which is the same for ubase64. The only option was to use !pip install circuitpython-base64 which does not include b32decode. I read that base64 comes with Python by default which does not seem to be the case here. Is there any workaround?
base64 library for circuitpython on SEEED Xiao ESP32-C3
157 Views Asked by Aditya Desai At
2
There are 2 best solutions below
1
On
circuitpython-base64 does include b32decode! If you want to take a look at the source it is here. After running pip install circuitpython-base64, the following script should work.
import circuitpython_base64 as base64
bytes_to_encode = b"Aladdin:open sesame"
print(repr(bytes_to_encode))
base32_string = base64.b32encode(bytes_to_encode)
print(repr(base32_string))
decoded_bytes = base632.b32decode(base32_string)
print(repr(decoded_bytes))
Reffering to: https://learn.adafruit.com/circuitpython-totp-otp-2fa-authy-authenticator-friend/software
I found that I can use the defined base 32 decoding function to decode a given base32 encoded value: