Strings must be encoded before hashing
当我们将字符串传递给 hash 算法时,会出现 “TypeError: Strings must be encoded before hashing”。
解决错误,使用encode()
import hashlib, time标签:format,token,encoded,before,Strings,md5,hashing From: https://www.cnblogs.com/beichengshiqiao/p/16967453.html
def get_token(username, token_id):
timestamp = int(time.time())
md5_format_str = "%s\n%s\n%s" % (username, timestamp, token_id)
obj = hashlib.md5()
obj.update(md5_format_str.encode())
print("token format:[%s]" % md5_format_str)
print("token :[%s]" % obj.hexdigest())
return obj.hexdigest()[10:17], timestamp