Django advanced beginner here. I'm banging my head against the wall trying to figure this one out. I have a simple webapp that uses twython_django_oauth tied into contrib.auth to register and login users. (I'm using twython out of the box with no modifications.) I can register new users via Twitter without a problem, which returns them to the app as a logged in user. Subsequent attempts to log in the user, however, returns this error:
Traceback:
File "/app/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/app/thislist/twython_django_oauth/views.py" in thanks
80. login(request, user)
File "/app/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in login
82. request.session[BACKEND_SESSION_KEY] = user.backend
Exception Type: AttributeError at /thanks
Exception Value: 'AnonymousUser' object has no attribute 'backend'
The one anomaly I notice is that in the Twitter accounts of the registered users that encounter this problem, the webapp shows up as authorized twice. Incidentally, this all seemed to be working fine a few weeks ago. I have two registered Twitter users that can log in without a problem. In those accounts, the app appears to be authorized only once. However, I can't seem to dial back the app to the point when these users registered to figure out what changes I made that may have caused the problem. If anyone has any insight into why the workflow here is returning AnonymousUser despite the user seeming to be registered with the appropriate credentials, I'd appreciate hearing from you!
Update: I've zeroed in on the cause of the problem. Each time the user is redirected back to the app after successfully entering their Twitter credentials, twython_django tries to log him/her in using a new 'oauth_token_secret' rather than grabbing the secret token generated during registration and stored in the webapp's Twitter profile database. As a result, django can't authenticate the user. So the question is: Why doesn't this
try:
user = User.objects.get(username = authorized_tokens['screen_name'])
generate a user object with the stored secret token.