If you want to execute in python3 you should do the following:
#python 3
import hmac
import hashlib
nonce = 1
customer_id = 123456
API_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)