I had a script in Python2 that was working great.
def _generate_signature(data): return hmac.new(\'key\', data, hashlib.sha256).hexdigest()
You can use bytes literal: b'key'
b'key'
def _generate_signature(data): return hmac.new(b'key', data, hashlib.sha256).hexdigest()
In addition to that, make sure data is also bytes. For example, if it is read from file, you need to use binary mode (rb) when opening the file.
data
binary
rb