Unable to read an environmental variable using Python. I'm using Flask and would like to use a Key whose value is stored in an environmental variable.
I stored my key using the export command, and tried to read the value using the key in python using the OS Module
- I stored the value in the Environmental Variable using :
export KEY123=xxx123xxxABCxxx789
- In python (Flask application) I'm trying to read the value using the following code :
import os
app.config['KEY'] = os.environ['KEY123']
- When I run my script I'm getting the error :
File ".../2.7/lib/python2.7/UserDict.py", line
23, in __getitem__
raise KeyError(key)
KeyError: 'KEY123'
What exactly is done wrong here.
P.S : If I print the value in my commandline using
print(os.environ['KEY123']), it works!
The Environmental variable is not present if I print using 'printenv' in other terminals. I'm doing this to avoid accidental commits to repositories