# MD5加密 # import hashlib def encrypt_md5(str=''): md = hashlib.md5() # 创建md5对象 md.update(str.encode(encoding='utf-8')) # 这里必须用encode()函数对字符串进行编码,不然会报 TypeError: Unicode-objects must be encoded before hashing return md.hexdigest() # 加密 # 调用 print(encrypt_md5('hello world')) 输入结果: 5eb63bbbe01eeed093cb22bb8f5acdc3