let say i got string(that is supposed to be a bytes):
"b'YzJGNVltYzJGNVltOTBlbk5oZVdKdmRIcHpZWGxpYjNSNmMyRjVZbTkwZW5OaGVXSnZkSHB6WVhsaWIzUjZjMkY1WW05MGVnOTBlblJsYzNRPXNheWJvdHo='"
and i want to decode it but it say it got to be in bytes so i got to turn that to this somehow
b'YzJGNVltYzJGNVltOTBlbk5oZVdKdmRIcHpZWGxpYjNSNmMyRjVZbTkwZW5OaGVXSnZkSHB6WVhsaWIzUjZjMkY1WW05MGVnOTBlblJsYzNRPXNheWJvdHo='
i am working on a chat client and when it sent the data(bytes), it turn into a string somehow when passing though the server and when it reach the other side, it can't decode it
ps: it is ENCRYPT, decoding that will give random number and letters, the client will decrypt it
oh, and, i don't really know if the '=' sign is supposed to be there, when i got the data in a test between me and my friend, i got it like that string(the one on the top) with the error saying that it got to be in byte.
part of the code in the client(just one line to show everyone, the rest is a secret):
base64.b64decode(that_string).decode('ascii')
it mainly use ascii so i think this is right, right?
more info:
base64.b64encode(message.encode('ascii'))
the message here is for getting the string sent from the other side
Room.message(str(secretEncrypt(par, codes())))
i don't know how i miss this, it str it before it send =.= well, it still need to turn it to bytes, how so i do that?
repr(data)instead of justdata. Show the code doing the sending and we can fix the right problem.base64.b64encode(...)returns bytes, so how is it sent to the client?bytesthrough astrwithout decoding/encoding (in other words, send each byte as the Unicode codepoint with the same number). This isn't impossible—but it's almost always a sign that you're doing something wrong. There's almost always a better answer. For example: If your API is byte-based, usebytesinstead ofstrin the API; if yourbytesare ASCII (which is always true for base64), justb.decode('ascii')to get thestr; etc.