import hashlib import base64 a=hashlib.md5() a.update("123456".encode("utf-8")) print(base64.b64encode(a.digest()).decode('utf-8'))