init .py
from flask_wtf import FlaskForm
from wtforms import StringField,SubmitField,PasswordField
from wtforms.validators import DataRequired,Length,Email
from flask import Flask
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
import os
app = Flask(__name__)
app.config['SECRET_KEY'] = 'r3t058rf3409tyh2g-rwigGWRIGh[g'
app.config['MAIL_SERVER']='smtp.googlemail.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_PASS')
mail=Mail(app)
db = SQLAlchemy(app)
logMg=LoginManager(app)
logMg.login_view='login'
logMg.login_message_category='info'
bcrypt=Bcrypt()
from portfolio import routes
Routes.py
def send_reset_email(user):
token=user.get_reset_token()
msg=Message('Password Reset Request',sender='noreply@demo.com',recipients=[user.email])
msg.body=''' To reset your password visit the following link:
{ url_for('reset_token',token=token,_external=True) }
If you did not Make request please contact our Team
'''
mail.send(msg)
@app.route("/reset_password",methods=['GET','POST'])
def reset_request():
if current_user.is_authenticated:
return redirect(url_for('admin'))
form=RequestResetForm()
if form.validate_on_submit():
user=User.query.filter_by(email=form.email.data).first()
send_reset_email(user)
flash('Reset Email Link Sent')
return redirect(url_for('login'))
return render_template("reset_request.html",form=form,legend='Edit Post')
@app.route("/reset_password/<token>",methods=['GET','POST'])
def reset_token():
if current_user.is_authenticated:
return redirect(url_for('admin'))
user=User.verify_reset_token(token)
if user is None:
flash('Invalid or Expired Token','warning')
return redirect(url_for(reset_request))
form=ResetPasswordForm()
if form.validate_on_submit():
hashed_password=bcrypt.generate_password_hash(form.password.data).decode('utf-8')
user.password=hashed_password
db.session.commit()
flash('Password Changed!','success')
return redirect(url_for('Login'))
return render_template('reset_token',form=form,legend='Reset Password Form')
Продолжайте получать эту ошибку для проверки подлинности отправителя. Я пытался изменить свой адрес электронной почты. и включил настройку IMAP, но не работал
Возвращает
smtplib.SMTPSenderRefused smtplib.SMTPSenderRefused: (530, b'5.7.0 Требуется проверка подлинности. Подробнее см. \ n5.7.0 https://support.google.com/mail/?p=WantAuthError t20sm2139075wmi.2 - gsmtp ',' noreply@demo.com ')
Traceback (последний вызов последнего) Файл «C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py ", строка 2464, в call return self.wsgi_app (Environment, start_response)
File" C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py ", строка 2450, в wsgi_app response = self.handle_exception (e)
File" C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py ", строка 1867, при повторном повышении handle_exception (exc_type, exc _value, tb)
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask_compat.py", строка 39, при повторном повышении значения повышения
Файл "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py", строка 2447, в wsgi_app response = self.full_dispatch_request ( )
Файл "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py", строка 1952, в full_dispatch_request rv = self. handle_user_exception (e)
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py", строка 1821, в повторном вызове handle_user_exception (exc_type, exc_value, tb)
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask_compat.py", строка 39, при повторном повышении повысить значение
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-package s \ flask \ app.py ", строка 1950, в full_dispatch_request rv = self.dispatch_request ()
File" C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask \ app.py ", строка 1936, в dispatch_request return self.view_functionsrule.endpoint
File" C: \ Dev \ Visual Studio 2019 \ Projects \folio \folio \ routes.py ", строка 177, в reset_request send_reset_email (user)
File" C: \ Dev \ Visual Studio 2019 \ Projects \folio \ портфолио \ routes.py ", строка 168, в send_reset_email mail.send ( msg)
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask_mail.py", строка 492, в send message.send (connection )
Файл "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask_mail.py", строка 427, в send connection.send (self)
Файл «C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ site-packages \ flask_mail.py» , строка 192, в send message.rcpt_options)
File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ smtplib.py", строка 867, в sendmail raise SMTPSenderRefused (код, соответственно from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Требуется аутентификация. Подробнее: \ n5.7.0 https://support.google.com/mail/?p=WantAuthError t20sm2139075wmi.2 - gsmtp ',' noreply@demo.com ')