Server seemingly randomly spitting out error messages: Exception occurred processing WSGI script

StackOverflow https://stackoverflow.com/questions/21385282

  •  03-10-2022
  •  | 
  •  

Question

At work our host has recently configured our server to run multiple Django projects side-by-side, but something is not quite right. There are two main problems.

  1. Changes do not immediately go into effect. When a site is first deployed (or changed), there will be a period of latency of a couple hours. This usually means incessant 500 errors.

  2. Once everything settles down, the sites work some of the time, but they will randomly break. They first said there were no error messages, but they finally gave me permissions to check the logfiles. It seems to be arbitrarily loading different parts of the different settings files all willy-nilly. In the traceback below, a request is made from URL 1, then the server looks in the directory for URL 2 and tries to load the settings module defined in the wsgi.py for URL 3. But like I said, this doesn't happen every time. Sometimes the sites are loaded correctly.

I have tested these projects on my own host and everything works as expected, but I don't have permissions at the host here to check the exact configurations for httpd.conf and other various necessary things. I also don't have enough experience with apache to guess blindly as to what the problem is, so I'm at a loss here. What are some specific configuration questions I should be asking?

Thanks in advance.

 mod_wsgi (pid=####): Exception occurred processing WSGI script '/srv/www/**<url-project 1>**/wsgi.py'.
  Traceback (most recent call last):
   File "/srv/www/**<url-project 2>**/.local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
     self.load_middleware()
   File "/srv/www/**<url-project 2>**/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
     for middleware_path in settings.MIDDLEWARE_CLASSES:
   File "/srv/www/**<url-project 2>**/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
     self._setup(name)
   File "/srv/www/**<url-project 2>**/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
     self._wrapped = Settings(settings_module)
   File "/srv/www/**<url-project 2>**/.local/lib/python2.7/site-packages/django/conf/__init__.py", line 134, in __init__
     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
 ImportError: Could not import settings '**<url-project 3>**.settings.production' (Is it on sys.path?): No module named **<url-project 3**>.settings.production
Was it helpful?

Solution

Make sure you read:

Do not use os.environ.setdefault() in the WSGI script file as is now generated by Django. Change it os.environ[…] instead.

OTHER TIPS

Graham's answer was helpful. To anyone else having the same problem, I'd also like to point out the section on WSGIApplicationGroup that says each wsgi application should be run on it's own python sub-interpreter.

more info here: http://modwsgi.readthedocs.org/en/latest/configuration-directives/WSGIApplicationGroup.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top