Python encoded message with HMAC-SHA256 Python encoded message with HMAC-SHA256 python python

Python encoded message with HMAC-SHA256


If you want to execute in python3 you should do the following:

#python 3import hmacimport hashlibnonce = 1customer_id = 123456API_SECRET = 'thekey'api_key = 'thapikey'message = '{} {} {}'.format(nonce, customer_id, api_key)signature = hmac.new(bytes(API_SECRET , 'latin-1'), msg = bytes(message , 'latin-1'), digestmod = hashlib.sha256).hexdigest().upper()print(signature)


You're using numbers where the api expects a string/bytes.

# python 2import hmacimport hashlibnonce = 1234customer_id = 123232api_key = 2342342348273482374343434API_SECRET = 892374928347928347283473message = '{} {} {}'.format(nonce, customer_id, api_key)signature = hmac.new(    str(API_SECRET),    msg=message,    digestmod=hashlib.sha256).hexdigest().upper()print signature