# !/usr/bin/env python3
import random
import string
TEXT = string.punctuation + string.ascii_letters + string.digits
s1 = ''.join(random.sample(TEXT,k=32))
s3 = ''.join(random.choices(TEXT,k=32))
print('punctuation:', string.punctuation)
print('ascii_letters:', string.ascii_letters)
print('digits:', string.digits)
print(s1)
print(s3)
'''
punctuation: !"#$%&'()*+,-./:;<=>?@[]^_`{|}~
ascii_letters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
digits: 0123456789
)c^-,S`9OYyKmI/:Xdx8;jD>n'E7VMf
q.j$<A!hCh[~Z|$60p?j`"3,YxZL0ovk
'''
import base64
import uuid
print('随机uudi4:', uuid.uuid4())
ckst = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
print('ckst:', ckst)
'''
随机uudi4: 7de883e4-3086-44ea-82ef-b10fe4d4c985
ckst: b'8WYudFdQS+eZULOI5+3extP47xgsXEdPlwW6x8I5l2Q='
'''
参考:
Basic authentication on Tornado with a decorator https://gist.github.com/guillaumevincent/4771570
Python 生成一段随机字符串的两种写法 https://www.v2ex.com/t/394944
Python 生成随机字符串 https://www.jianshu.com/p/8c8763af7465