0

I have built an application in python/flask and try to deploy it using Heroku. I have stored the credentials like an API-Key in a .env file. When running locally, everything seems to work and the code successfully receives the API Key from the env-file. When running on Heroku however, I get error messages regarding the missing key. When putting the key directly in the code, everything works – also in production.

To be clear, I integrated the .env file in the .gitignore file, so its not uploaded to github. As I am still quite the noob regarding webdevelopment, I am not sure what I am missing. Also, if the .env file is not in github, where does the code get the credentials from?

This is how the beginning of my file looks like

from dotenv import load_dotenv
import os

load_dotenv()

HERE_API_KEY = os.getenv("HERE_API_KEY")

In the .env file the key is stored like this: HERE_API_KEY=example12345

  • I think you've answered your own question: "*I integrated the .env file in the .gitignore file, so its not uploaded to github*". Then that means, it also won't be available to your Heroku deployment, because the code running on your Heroku dyno doesn't have that .env file. This is correct because you don't want to commit secrets to your repo. – Gino Mempin Feb 23 '22 at 12:42
  • Thanks Gino, so as I understood from the linked question, .env doesnt make sense on Heroku and can be best done by configuering it directly in the Heroku dashboard. – The guy With hat Feb 23 '22 at 13:04
  • Yes, the Heroku way is to use Config Vars, and then read them in your code same just like environment variables. If you've got a lot of stuff on your local .env, you can use some `xargs` "magic": https://stackoverflow.com/a/66184812/2745495 – Gino Mempin Feb 23 '22 at 13:09

0 Answers0