Forums

os.getenv('API_KEY') returns none

Hello,

I'm new to Python and PythonAnywhere and I have a Flask app that works completely fine locally where all my environment variables for API credentials are in a '.env' file. I used 'os.getenv('API_KEY')' to access any of them when running locally but it always returns 'None' on PythonAnywhere. How can I get it to work?

You'll need to load the .env file in your WSGI file (which you can edit via the link on the "Web" page). Here's a link to a help page with the details.