I had it arranged so that the setting, ‘SECRET_KEY,’ was looking for the variable, ‘DJANGO_SECRET_KEY’ (as well as the database password, “DJANGO_DB_KEY’). But just to make sure, I changed ‘DJANGO_SECRET_KEY’ to ‘SECRET_KEY’ in settings.py and in the config file, with no success.
I have the SetEnv text, below, as an Additional Apache Directive, which lands in the /var/www/vhosts/system/coachcpredictor.com.conf/vhost.conf file and –/vhost_ssl.conf file. I’m using Plesk, so the main configuration files are auto-generated each time Apache restarts or when the files get rebuilt. One of my questions has been how to make sure the SetEnv directive gets into the correct config file.
DocumentRoot /var/www/vhosts/coachcpredictor.com/mFBP
WSGIScriptAlias / /var/www/vhosts/coachcpredictor.com/mFBP/mFBP/wsgi.py
SetEnv SECRET_KEY [##################]
SetEnv DJANGO_DB_KEY [#########]
<Directory /var/www/vhosts/coachcpredictor.com/mFBP/mFBP>
Require all granted
Nginx is running behind Apache, serving static files.
Here is the traceback, and then the text of the wsgi.py file, then the text of the settings.py file:
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
mod_wsgi (pid=1160235): Failed to exec Python script file ‘/var/www/vhosts/coachcpredictor.com/mFBP/mFBP/wsgi.py’. |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
mod_wsgi (pid=1160235): Exception occurred processing WSGI script ‘/var/www/vhosts/coachcpredictor.com/mFBP/mFBP/wsgi.py’. |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
Traceback (most recent call last): |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/var/www/vhosts/coachcpredictor.com/mFBP/mFBP/wsgi.py”, line 17, in |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
application = get_wsgi_application() |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3/dist-packages/django/core/wsgi.py”, line 12, in get_wsgi_application |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
django.setup(set_prefix=False) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3/dist-packages/django/_init_.py”, line 19, in setup |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
^^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3/dist-packages/django/conf/_init_.py”, line 102, in _getattr_ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
self._setup(name) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3/dist-packages/django/conf/_init_.py”, line 89, in _setup |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
self._wrapped = Settings(settings_module) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3/dist-packages/django/conf/_init_.py”, line 217, in _init_ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
mod = importlib.import_module(self.SETTINGS_MODULE) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/usr/lib/python3.12/importlib/_init_.py”, line 90, in import_module |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
return _bootstrap._gcd_import(name[level:], package, level) |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap>”, line 1387, in _gcd_import |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap>”, line 1360, in _find_and_load |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap>”, line 1331, in _find_and_load_unlocked |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap>”, line 935, in _load_unlocked |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap_external>”, line 995, in exec_module |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “<frozen importlib._bootstrap>”, line 488, in _call_with_frames_removed |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “/var/www/vhosts/coachcpredictor.com/mFBP/mFBP/settings.py”, line 24, in |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
SECRET_KEY = os.environ[“SECRET_KEY”] |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
~~~~~~~~~~^^^^^^^^^^^^^^ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
File “”, line 685, in _getitem_ |
|
|
|
Apache error |
2025-09-23 14:46:19 |
Error |
5.161.41.211 |
|
KeyError: ‘SECRET_KEY’ |
|
|
|
Apache error |
import sys
import os
sys.path.insert(0, ‘/var/www/vhosts/coachcpredictor.com/mFBP’)
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘mFBP.settings’)
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
#Build paths inside the project like this: BASE_DIR / ‘subdir’.
BASE_DIR = Path(file).resolve().parent.parent
#Quick-start development settings - unsuitable for production
#See Deployment checklist | Django documentation | Django
#SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ[“SECRET_KEY”]
if not SECRET_KEY:
raise ImproperlyConfigured(“The DJANGO_SECRET_KEY environmental variable is not set.”)
#SECURITY WARNING: don’t run with debug turned on in production!
DEBUG = False