0

Im having this error on the console

File "c:\Users\onlyj\Desktop\Repo Git\Flask\Flask App\main\routes.py", line 192, in send_reset_email token = user.get _reset_token()
AttributeError: 'User' object has no attribute'get_reset_to ST /reset_password HTTP/1.1" 500 -

def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request', 
                   sender      = 'onlyjungletom@gmail.com', 
                   recipients  = [user.email])

    msg.body = f'''To reset yor password, visit the following link:
{url_for('reset_token', token = token, _external = True)}

If you did not make this request then simply ignore this email and no changes will be made.
'''
    mail.send() 

So, when i hit the "Send pass reset "button on the web page i get this error "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

And this is the User model on models.py :

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key = True)
    username    = db.Column(db.String(20),  unique   = True, nullable = False)
    email       = db.Column(db.String(120), unique   = True, nullable = False)
    image_file  = db.Column(db.String(20),  nullable = False, default = 'default.jpg')
    password    = db.Column(db.String(60),  nullable = False)
    posts       = db.relationship('Post',   backref  = 'author', lazy = True)
    
    def __repr__(self):
        return f"User('{self.username}'), '{self.email}', '{self.image_file}')"
  • Thanks, so the problem is that you are trying to reference an attribute of the 'User' model with `user.get_reset_token()`. Your user model does not have this feature yet, and is therefore returning an error. One way to fix this would be to change your 'User' model to include the `get_reset_token()` part as shown [here](https://github.com/CoreyMSchafer/code_snippets/blob/master/Python/Flask_Blog/10-Password-Reset-Email/flaskblog/models.py). – Patrick Yoder Feb 25 '22 at 23:03
  • Now im having this issue, i put all like the page you sended. File "C:\Users\onlyj\AppData\Local\Programs\Python\Python310\lib\site-packages\itsdangerous\signer.py", line 195, in derive_key bytes, self.digest_method(self.salt + b"signer" + secret_key).digest() TypeError: unsupported operand type(s) for +: 'int' and 'bytes' 127.0.0.1 - - [25/Feb/2022 21:16:03] "POST /reset_password HTTP/1.1" 500 - –  Feb 26 '22 at 00:17
  • 1
    Hmm, have you done exactly like [this](https://www.youtube.com/watch?v=vutyTx7IaAI&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH) video by Corey Schafer explains? I've worked through his course and didn't have issues with this part, so maybe you are missing something in one of your other files? Also, [this](https://stackoverflow.com/questions/46486062/the-dumps-method-of-itsdangerous-throws-a-typeerror) question might help? – Patrick Yoder Feb 26 '22 at 08:13
  • 1
    I figured out that the problem was mail.send() im trying to send the email to my gmail but it doesnt work, when i remove that email.send it works fine, but it doesnt send it obviously –  Feb 26 '22 at 21:57
  • 1
    Yes, I've had a similar problem. Is the error called `smtplib.SMTPAuthenticationError`? If so, [this](https://stackoverflow.com/questions/34926570/flask-securitys-flask-mail-registration-receives-smtplib-smtpauthenticationerro) post helped me and might be of use to you. – Patrick Yoder Feb 26 '22 at 22:00

0 Answers0