June 2018
Beginner
508 pages
13h 8m
English
Again, we have three functions that all produce a token, albeit in different formats. Let's see the example:
# secrs/secr_rand.pyprint(secrets.token_bytes(16))print(secrets.token_hex(32))print(secrets.token_urlsafe(32))
The first one, token_bytes, simply returns a random byte string containing n bytes (16, in this example). The other two do the same, but token_hex returns a token in hexadecimal format, and token_urlsafe returns a token that only contains characters suitable for being included in a URL. Let's see the output (which is a continuation from the previous run):
b'\xda\x863\xeb\xbb|\x8fk\x9b\xbd\x14Q\xd4\x8d\x15}'9f90fd042229570bf633e91e92505523811b45e1c3a72074e19bbeb2e5111bf7bl4qz_Av7QNvPEqZtKsLuTOUsNLFmXW3O03pn50leiY ...
Read now
Unlock full access