I have find this similar solution in Python language.
Base64 encoding enables us to convert bytes containing binary or text data to ASCII characters. By encoding the data, we improve the chances of it being processed correctly by various systems. Some systems don’t understand the data in bytes format, so we have to convert the data.
To convert the Image to Base64 String in Python we have to use the Python base64 module that provides b64encode() method.
The purpose of the base64.b64encode() method in Python is to convert the binary data into ASCII-safe “text”. But Python strongly disagrees with that. Python is now very strict about this that bytes.encode() method doesn’t even exist, and so ‘xyz’.encode(‘base64’) would raise an AttributeError.