'Python Fernet TypeError: token must be bytes although the input are bytes

I have encrypted values in a mongo database and want to decrypt them. So i find the data in the database and access it like this:

for c in conversation_list:
    for m in c['messages']:
        print(m['content']) 

this prints b'gAAAAABiCMy6enO6UtropwNB6swjB2WqNthx-abULtxsQMqUKw9R0a7HXZLFEklTTZqc04NIxExTPDQk6xkrvnBKXyj8K5CtHFzg_b8w7RcX0ma36TnXM8g='

print(fernet.decrypt(m['content']))

And this raises the typeerror.

I don't understand what I'm doing wrong. I have encrypted a test string exactly the same way in a test file and can decrypt it without a problem, but as soon as I load the data from the database, I get this error.

Edit: Some further testing revealed, that python does not interpret the byte string as bytes, but as a normal string. How do I get python to understand that this is in fact a byte string?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source