AttributeError: 'WSGIRequest' object has no attribute 'session'

kingsley picture kingsley · Jul 14, 2010 · Viewed 7.2k times · Source

I keep getting this error at random times and whenever I touch the django.wsgi file, it gets fixed only to happen again after a few hours. I'm lost as to what to do. my middleware_classes is as follows:

MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.facebookConnectMiddleware.FacebookConnectMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

The error always occurs in the facebook middleware when i do an "if request.session" statement. Thanks

Answer

Jonatan Littke picture Jonatan Littke · May 21, 2012

Make sure the SessionMiddleware is first in your MIDDLEWARE_CLASSES.