I'm working on Debian Jessie with Python 2. Why can't Python's environ
see environment variables that are visible in bash?
# echo $SECRET_KEY
xxx-xxx-xxxx
# python
>>> from os import environ
>>> environ["SECRET_KEY"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/.virtualenvs/prescribing/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'SECRET_KEY'
I set these environment variables using /etc/environment
- not sure if that's relevant:
SECRET_KEY=xxx-xxx-xxx
I had to run source /etc/environment
to get bash to see them, which I thought was strange.
UPDATE: printenv SECRET_KEY
produces nothing, so I guess SECRET_KEY
is a shell not an environment variable.