question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

user.is_authenticated AttributeError: can't set attribute

See original GitHub issue

In the sample code:


@login_manager.request_loader
def request_loader(request):
    email = request.form.get('email')
    if email not in users:
        return

    user = User()
    user.id = email

    # DO NOT ever store passwords in plaintext and always compare password
    # hashes using constant-time comparison!
    user.is_authenticated = request.form['pw'] == users[email]['pw']

    return user

When username is correct and password is incorrect, get follow error message:

user.is_authenticated = request.form['pw'] == users[email]['pw']
AttributeError: can't set attribute

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

5reactions
davidismcommented, Jan 20, 2017

All users that aren’t anonymous are authenticated, it’s not a property you need to set. Instead, if the passwords don’t match, just don’t return a user object at all.

4reactions
PyAntonycommented, Feb 21, 2019

Someone needs to fix that documentation. This is not correct: user.is_authenticated = request.form[‘pw’] == users[email][‘pw’]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django login - getting an AttributeError can't set attribute
Django login - getting an AttributeError can't set attribute ... if the existing session corresponds to a different 68 # authenticated user.
Read more >
[Solved] AttributeError: can't set attribute in python - Finxter
Fix #1: Use the namedtuple.​​ The easiest way to fix the AttributeError:can't set attribute is to create a new namedtuple object with the...
Read more >
Request object does not allow attributes to be set
... I get an 'AttributeError: can't set attribute' when attempting to set the user attribute on the request object: request.session[SESSION_KEY] = user.id
Read more >
django.contrib.auth
This is a way to tell if the user has been authenticated. This does not imply any permissions and doesn't check if the...
Read more >
Customizing authentication in Django
Once a user has authenticated, Django stores which backend was used to ... This change can't be done automatically and requires manually fixing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found