from urllib import parse import hashlib ''' MD5加密: 1。对请求的参数进行ascill码排序 ---> dict(sorted(dict1.items(),key=lambda item:item[0])) 2。对url 进行encode编码 --->datas = parse.urlencode(req) 3。做MD5加密 生成sign(密钥) ---> MDfive = hashlib.md5() MDfive.update(datas.encode('utf-8') return MDfive.hexdigest() ''' def MD5(**kwargs): req = dict(sorted(kwargs.items(), key=lambda item: item[0])) datas = parse.urlencode(req) MDfive = hashlib.md5() MDfive.update(datas.encode('utf-8')) return MDfive.hexdigest() print(MD5(name = 'shenqiang',age = '28'))