If I call os.urandom(64), I am given 64 random bytes. With reference to Convert bytes to a Python string I tried
a = os.urandom(64)
a.decode()
a.decode(\"utf
You can use base-64 encoding. In this case:
a = os.urandom(64)
a.encode('base-64')
Also note that I'm using encode
here rather than decode
, as decode
is trying to take it from whatever format you specify into unicode. So in your example, you're treating the random bytes as if they form a valid utf-8
string, which is rarely going to be the case with random bytes.