kingsley
kingsley

Reputation: 305

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

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

Upvotes: 9

Views: 7360

Answers (4)

Jonatan Littke
Jonatan Littke

Reputation: 5663

Make sure the SessionMiddleware is first in your MIDDLEWARE_CLASSES.

Upvotes: 6

Taranttini
Taranttini

Reputation: 1435

Check if in your code you have write:

del request.session

the correctly are is

del request.session['YOU VARIABLE']

Upvotes: 0

Graham Dumpleton
Graham Dumpleton

Reputation: 58563

Try the alternate WSGI script file documented at end of:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

Report back to mod_wsgi list if that helps as we are trying still to uncover what if any problems that alternate WSGI script is solving, so can work out whether a real problem or whether users aren't using Django properly.

Upvotes: 0

godswearhats
godswearhats

Reputation: 2255

Are you using Apache? If so, you should probably restart httpd after you modify the mod_wsgi file.

sudo apachectl -k restart
sudo apache2ctl -k restart
sudo /etc/init.d/httpd restart

... or similar should work. If you're still seeing the problem, try pasting in the full error message.

Upvotes: 0

Related Questions