0

I'm trying to add the ability to reset a user's password with a password reset link with Flask but whenever I go to test out the functionality of this feature, I'm met with ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.

Here's the revelant snippets of code from my app.py and init.py. If this isn't enough to solve the problem, just let me know what else you need to see.

app.py

def send_reset_email(user):
token = user.get_reset_token()
msg = Message('Password Reset Request')
msg.sender = 'noreply@demo.com'
msg.recipients = [user.email]
msg.body = f"""
To reset your password, visit the following link: {url_for('reset_token', token=token, _external=True)}. 
If you did not make this request, then ignore this email and no changes will be made.
"""
mail.send(msg)


@app.route("/reset_password", methods=['GET', 'POST'])
def reset_password():
if current_user.is_authenticated:
    return redirect(url_for('home'))
form = RequestResetForm()
if form.validate_on_submit():
    user = User.query.filter_by(email=form.email.data).first()
    send_reset_email(user)
    flash('An email has been set with instructions to reset your password.', 'info')
    return redirect(url_for('login'))
return render_template('reset_request.html', title='Reset Password', form=form)

init.py

app = Flask(__name__)
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
mail = Mail()
mail.init_app(app)

app.config['SECRET_KEY'] = 'f645748071241866b90c405a391033ac'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('EMAIL_USER')
app.config['MAIL_PASSWORD'] = os.environ.get('EMAIL_USER')
app.config['MAIL_SUPPRESS_SEND'] = False
  • 3
    Where, exactly, does this error appear? In your browser? In the terminal session where the flask server is running? Somewhere else? – John Gordon Mar 27 '22 at 00:45
  • 1
    always put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Mar 27 '22 at 04:06
  • always put code with correct indentations because indetation can change everything in Python code and we can't see what is real problem and what is only wrong copied code. – furas Mar 27 '22 at 04:07
  • Does this answer your question? [Errno 10061 : No connection could be made because the target machine actively refused it ( client - server )](https://stackoverflow.com/questions/12993276/errno-10061-no-connection-could-be-made-because-the-target-machine-actively-re) – Patrick Yoder Mar 27 '22 at 07:35

0 Answers0