Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:02:44+00:00 2026-05-28T06:02:44+00:00

Django advanced beginner here. I’m banging my head against the wall trying to figure

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:02:45+00:00Added an answer on May 28, 2026 at 6:02 am

    When you are logging in for the first time, the example code creates a new django user with username=authorized_tokens[‘screen_name’] and password = authorized_tokens[‘oauth_token_secret’].
    The second time when you login, the authorized_tokens[‘oauth_token_secret’] changes, so if you use the changed token to authenticate, it will return AnonymousUser since the password is wrong.

    To make it work, add the following lines after:

    user = User.objects.get(username = authorized_tokens['screen_name'])
    user.set_password(authorized_tokens['oauth_token_secret'])
    user.save()
    

    Hope this answer is clear. Please feel free to ask questions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to the fantastic inline model formsets in django I have a pretty advanced
I know this sounds kind of stupid, but as a beginner in Django (and
I have a Django application using django-mssql to communicate w/ SQL Server. This works
I've posted this on django-users but haven't received a reply! So I have my
I am a Django Beginner. I found this Django snippet to show a simple
Hello and thank you in advance, I am trying to create a django form
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
Django code samples involving post data often shows code similar to this: if request.method
I'm new to Django, so apologies in advance if this is a rookie issue.
I have django form which displays the check boxes.After selecting the checkboxes user will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.