我的python脚本目前使用os.environ ['SECRET_KET']。 服务器使用系统服务启动:
[Unit]
Description=Escota Dev Service
After=multi-user.target
[Service]
Type=simple
User=vagrant
WorkingDirectory=/var/www/myproject
ExecStart=/var/www/myproject/env/bin/python web/myproject_project/manage.py runserver 127.0.0.1:8000
Restart=on-abort
[Install]
WantedBy=multi-user.target
服务正在运行:
● myproject-dev.service - myproject Dev Service
Loaded: loaded (/lib/systemd/system/myproject-dev.service; enabled; vendor preset: enabled)
Active: active (running) since mer. 2018-09-19 10:18:35 CEST; 179ms ago
Main PID: 10081 (python)
Tasks: 1
Memory: 1.2M
CPU: 58ms
CGroup: /system.slice/myproject-dev.service
└─10081 /var/www/myproject/env/bin/python web/myproject_project/manage.py runserver 127.0.0.1:8000
sept. 19 10:18:35 vm systemd[1]: Started myproject Dev Service.
最后,错误消息:
[CRITICAL] -> 19/09/2018 09:10 : ('Environment(Config) Error ! => ', ConnectionError(MaxRetryError("HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /firerisk/zone/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe9b4d72b38>: Failed to establish a new connection: [Errno 111] Connection refused',))",),), <class 'requests.exceptions.ConnectionError'>)
但这不相关,因为真正的错误是:
Sep 19 10:18:39 vm python[10081]: File "/var/www/myproject/web/myproject_project/myproject_project/settings.py", line 30, in <module>
Sep 19 10:18:39 vm python[10081]: if os.environ['SECRET_KEY']:
Sep 19 10:18:39 vm python[10081]: File "/var/www/escota/env/lib/python3.5/os.py", line 725, in __getitem__
Sep 19 10:18:39 vm python[10081]: raise KeyError(key) from None
Sep 19 10:18:39 vm python[10081]: KeyError: 'SECRET_KEY'
你能帮我吗? 谢谢。
面料
答案 0 :(得分:0)
看来答案是:
sudo systemctl set-environment SECRET_KEY=blahblahblah