Bytes message argument error Bytes message argument error python-3.x python-3.x

Bytes message argument error


bytes() in Python 2.x is the same as str() and it accepts only one string argument.

Use just message = "Message" and secret = "secret". You don't even need bytes() here.


The likely reason you encountered this problem is the code you were using was written for Python 3.x and you executed it under Python 2.x.

I know someone has already partially stated this, but I thought it might be helpful to make it clearer to people new to Python who may not realize why the 'utf-8' argument was being used as the person asking the question noted that they did not know what the argument was for.

Anyone who comes here may find that useful in understanding why there was an argument of 'utf-8'.


try,

import hmacimport hashlibimport base64message = bytes("Message")secret = bytes("secret")signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())print(signature)