Airflow Exception: "raise InvalidToken cryptography.fernet.InvalidToken"

Author: Omid Vahdaty 5.4.2021

If you get this error of invalid token, it is because Airflow is using Fernet. Airflow encrypt all the passwords for its connections in the backend database.

Somehow Airflow backend is using previous fernet key and you have generated a key  which you have created in a new connection.

My recommendation is to do the following first:

This will help in deleting all the existing records in your backend db. NOTICE – this will delete all your Airflow connections and variables you inputted manually:

airflow resetdb
airflow initdb

This will initialize backend db like a fresh install db. Airflow may shout about missing variables.
Start Airflow and enter missing variables  one by one.

Then start airflow web server and scheduler.


——————————————————————————————————————————
I put a lot of thoughts into these blogs, so I could share the information in a clear and useful way.
If you have any comments, thoughts, questions, or you need someone to consult with,

feel free to contact me via LinkedIn:

2 thoughts on “Airflow Exception: “raise InvalidToken cryptography.fernet.InvalidToken””

  1. Thank you for this suggestion. I couldn’t find a solution to this anywhere until I found your post. Any idea how a new key is being generated? I added a DAG that populates my credentials to at least make errors go away until I fill out the connections manually. Or do you have any thoughts on best practice for populating credentials automatically?

    1. HI Kwood, Happy to help. Don’t have a idea, at the moment about populating password. let me know if you find a solution, I will be happy to add a blog about it and provide credit to you.

Leave a Reply