Since json.dumps is being used to serialize the data before encryption, a string is being passed to the cryptography package. In Python 2 strings are also bytes. In Python 3 they are not, so an explicit translation is required.
It appears that doing something like message.encode('utf-8') (if the Python version is 3.x) would make the cryptography package happy.
The
cryptography
package expects an instance ofbytes
to be sent to itsFernet.encrypt
method: https://github.com/pyca/cryptography/blob/master/cryptography/fernet.py#L63Since
json.dumps
is being used to serialize the data before encryption, astring
is being passed to thecryptography
package. In Python 2strings
are alsobytes
. In Python 3 they are not, so an explicit translation is required.It appears that doing something like
message.encode('utf-8')
(if the Python version is 3.x) would make thecryptography
package happy.