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.
3 thoughts on “Airflow Exception: “raise InvalidToken cryptography.fernet.InvalidToken””
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?
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.
The command is now “airflow db reset” in airflow 2+
https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#reset