7

I'm moving an application that uses django_cms from one server, where everything worked, to another and have spent the last 4 hours trying to find the cause of this error. A suggestions very welcome!

 mod_wsgi (pid=21972): Exception occurred within WSGI script '/var/www/vhosts/compdoctest.com/django/compdoc/django.wsgi'.
 Traceback (most recent call last):
   File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 230, in __call__
     self.load_middleware()
   File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 42, in load_middleware
     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
 ImproperlyConfigured: Error importing middleware cms.middleware.media: "No module named media"

The offending line is the last one in the middleware list in settings.py

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.multilingual.MultilingualURLMiddleware',
    'cms.middleware.media.PlaceholderMediaMiddleware',
    )

If I remove the final line then the code continues and falls over later saying that item is required in middleware.

I'm using slightly different version of django, 1.2.1 final on the old working server and 1.2.3 final on the new server.

All the things I've tried:

  • The same version of django_cms - 2.1.0 beta 3 - that was used on the old server
  • The latest version on github - 2.1.0.beta2-550 Putting the cms, mptt, menus, publisher folders in the
  • app From python importing the
  • googled (nobody having the same problem that I can find)
  • middleware file directly (no problem)

result of opening in python:

python manage.py shell        
Python 2.5.2 (r252:60911, Jan 20 2010, 23:14:04) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import cms.middleware.media
>>> cms.middleware.media.__file__
'/var/www/vhosts/compdoctest.com/django/compdoc/cms/middleware/media.pyc'
>>> from django.forms.widgets import Media
>>> import cms.middleware.media
>>> 

2 Answers 2

4

Thanks to my friend Bartosz Ptaszynski for pointing me in the right direction on this one. It was a path problem. Added this to the top of the settings.py file and it all magically started working.

sys.path.insert(0, '/path_to_app/app/')

And as he pointed out:

Exception occurred within WSGI script means that the path while running under the web server was wrong it's a completely different environment than the manage.py shell

3
  • Can you give a little more explanation of the problem and the solutions. Nov 7, 2010 at 16:21
  • The problem was simply that it couldn't find what it needed on the path. I think the old server was happy without a trailing / but this server was more fussy. Anyway adding the sys.path command above fixed the problem.
    – PhoebeB
    Nov 15, 2010 at 17:42
  • I had this problem and this solution did not work for me. However, inspired by this solution I also added: sys.path.insert(0, '/the/path/to/myapp/lib/python2.6/site-packages/') and it worked - or at least moved on to a new set of problems.
    – Tony Adams
    Dec 20, 2011 at 22:12
0

I had the same problem. But since it only occurs when using mod_wsgi, another solution is adding the path in the apache config (rather than editing the syspath inside setting.py):

    # mod_wsgi settings
WSGIDaemonProcess name user=user group=group python-path=/app_path/app/:/app_path/lib/python2.6/site-packages/:/app_path/
WSGIProcessGroup polykum

Including the site packages in the path is also given in the example of Jon Black.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.