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

I am getting below error at line(f = Fernet(private_key)).Please help to suggest

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-3x Questions

LEAVE A COMMENT