Generate HMAC SHA256 signature Python
Try using the hmac
module instead of the hashlib
module:
import hmac
import hashlib
secret_key = b"NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
total_params = b"/public/api/ver1/accounts/new?type=binance&name=binance_account&api_key=XXXXXX&secret=YYYYYY"
signature = hmac.new(secret_key, total_params, hashlib.sha256).hexdigest()
print("signature = {0}".format(signature))
This gives the desired result:
signature = 30f678a157230290e00475cfffccbc92ae3659d94c145a2c0e9d0fa28f41c11a