I had a function in Python 2 which I used to generate a 22 length random string from a UUID....
def make_base64_string():
return uuid.uuid4().bytes.encode("base64")[:22]
I have since started to test in Python 3 and just finished watching the Pragmatic Unicode presentation, most of which went way over my head. Anyway, I didn't assume this function would now work in Python 3.4 and I was right....
So next, I tried what I was hoping was the solution giving that bytes.encode
from my understating is gone... (treat everything as a byte, right?).
base64.b64encode(bytes(uuid.uuid4(), 'utf-8'))
but this gives me the following error...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: encoding or errors without a string argument
Why? I would like to understand this more.