postgresql - Secret Key environment variable not working on Ubuntu. Django, Postgres, Gunicorn, Nginx, Virtualenv -
this following error when try run makemigrations command while virtualenv active:
traceback (most recent call last): file "manage.py", line 22, in <module> execute_from_command_line(sys.argv) file "/home/tony/vp/vpenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line utility.execute() file "/home/tony/vp/vpenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 307, in execute settings.installed_apps file "/home/tony/vp/vpenv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) file "/home/tony/vp/vpenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = settings(settings_module) file "/home/tony/vp/vpenv/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__ mod = importlib.import_module(self.settings_module) file "/home/tony/vp/vpenv/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) file "<frozen importlib._bootstrap>", line 986, in _gcd_import file "<frozen importlib._bootstrap>", line 969, in _find_and_load file "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked file "<frozen importlib._bootstrap>", line 673, in _load_unlocked file "<frozen importlib._bootstrap_external>", line 665, in exec_module file "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed file "/home/tony/vp/vp/config/settings/production.py", line 1, in <module> .base import * file "/home/tony/vp/vp/config/settings/base.py", line 22, in <module> secret_key = os.environ["vp_secret_key"] file "/home/tony/vp/vpenv/lib/python3.5/os.py", line 725, in __getitem__ raise keyerror(key) none keyerror: 'vp_secret_key'
i have set environment variables inside 3 locations:
in virtual environments bin/activate script:
environment=vp_secret_key="****" environment=vp_db_pass="****"
in .bashrc file:
vp_secret_key="****" vp_db_pass="****"
and in gunicorn.service file:
[unit] description=gunicorn daemon after=network.target [service] user=tony environment=vp_secret_key="****" environment=vp_db_pass="****" group=www-data workingdirectory=/home/tony/vp/vp/ execstart=/home/tony/vp/vpenv/bin/gunicorn --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application [install] wantedby=multi-user.target
here how import in settings base.py (i use multiple settings files):
# security warning: keep secret key used in production secret! secret_key = os.environ["vp_secret_key"]
when echo them using $vp_secret_key value returned.
what can cause problem? setting them in multiple locations there sort of collission?
the problem viewing session variable
$ myname=tarun $ env
output of env won't show myname because variable in current bash. need export it
export vp_secret_key="****" export vp_db_pass="****"
edit 1
also if want can pass environment variable through gunicorn
execstart=/home/tony/vp/vpenv/bin/gunicorn -e vp_secret_key=***** --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application
Comments
Post a Comment