def toBase64 ( s ) : if isinstance ( s , str ) : s = s . encode ( "utf-8" ) return binascii . b2a_base64 ( s ) [ : - 1 ]
python base64 decode with b ahead of string
Represent string / bytes s as base64 omitting newlines
def toBase64(s):
    """Represent string / bytes s as base64, omitting newlines"""
    if isinstance(s, str):
        s = s.encode("utf-8")
    return binascii.b2a_base64(s)[:-1]