Fernet Decryption Error in cryptography python package

I am getting Fernet Decryption error error at line(f = Fernet(private_key)) .Please help on this.

Error:ValueError: Fernet key must be 32 url-safe base64-encoded bytes.

    from cryptography.fernet import Fernet
    import base64

    config_path = os.path.join(str(Utils.get_project_root()), 'key.pem')
    with open(config_path, "rb") as file_handle:
        private_key = file_handle.read()
    decoded_msg = base64.urlsafe_b64decode(encoded_text)
    f = Fernet(private_key)
    decrypted_msg = f.decrypt(decoded_msg)
    decrypted_msg.decode()

Source: Python Questions

LEAVE A COMMENT