简体   繁体   中英

Storing API_KEY in Heroku

I have a Python code that I want to run 24/7. After doing a bit research, I decided to deploy my code on Heroku. In order for my code to run, it needs to get an API key; however, I want to store the API key in a secure place.

So I stored the key in Heroku's config vars using the CLI's command config:set. However, I am not sure how to pull the key from config vars in order to store it in a variable in my code.

I am very new to all of this so I would really appreciate your help. I am open to storing my API key as well using different methods, whatever gets the job done in a beginner-friendly manner (git-crypt? etc.)

Thanks!

The configvar is an environment variable available to the application at runtime:

api_key = os.environ.get("API_KEY", "default_val")

You could have a default value on local dev (if needed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM