I had a script in Python2 that was working great.
def _generate_signature(data): return hmac.new(\'key\', data, hashlib.sha256).hexdigest()
try
codecs.encode()
which can be used both in python2.7.12 and 3.5.2
import hashlib import codecs import hmac a = "aaaaaaa" b = "bbbbbbb" hmac.new(codecs.encode(a), msg=codecs.encode(b), digestmod=hashlib.sha256).hexdigest()