【发布时间】:2020-07-08 09:36:00
【问题描述】:
我正在尝试通过烧瓶邮件向用户发送邮件。下面显示的代码在 localhost 上运行良好。但是,当我将烧瓶应用程序部署到 AWS Elastic Beanstalk 并使用 send_reset_email 函数时,它会抛出内部服务器错误。我应该在哪里更改我的代码?任何帮助将不胜感激。
我的配置代码:
application = Flask(__name__)
application.config['SECRET_KEY'] = '-------'
application.config["MONGO_URI"] = "mongodb+srv://------"
mongo = PyMongo(application)
db = mongo.db
bcrypt = Bcrypt(application)
application.config['MAIL_SERVER'] = 'smtp.googlemail.com'
application.config['MAIL_PORT'] = 587
application.config['MAIL_USE_TLS'] = True
application.config['MAIL_USERNAME'] = '----'
application.config['MAIL_PASSWORD'] = '----'
mail = Mail(application)
我的函数文件:
def get_reset_token(username, expires_sec=1800):
s = Serializer(application.config['SECRET_KEY'], expires_sec)
return s.dumps({'user': username}).decode('utf-8')
def verify_reset_token(token):
s = Serializer(application.config['SECRET_KEY'])
try:
username = s.loads(token)['user']
except:
return None
user = db.user.find_one({ 'username' : username })
return user
def send_reset_email(user):
token = get_reset_token(username=user['username'])
msg = Message('Password Reset Request',sender='----',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 simply ignore this email and no changes will be made.
'''
mail.send(msg)
【问题讨论】:
-
mail是什么?为什么是缩进的?您可以在哪里添加完整的错误回溯到您的问题? -
你能检查日志并显示错误的回溯吗?
-
@mtshaikh 我是初学者。我在 log\nginx\error 中找不到此错误的回溯。这就是这个文件的样子 2020/07/08 08:01:33 [warn] 32194#0: *39 客户端请求正文被缓冲到临时文件 /var/lib/nginx/tmp/client_body/0000000002,客户端:1.38.76.34,服务器:,请求:“POST /account HTTP/1.1”,主机:“blogbydarshan-env.eba-5yxwxghg.ap-south-1.elasticbeanstalk.com”,引用者:“blogbydarshan-env.eba-5yxwxghg.ap-south-1.elasticbeanstalk.com/…”跨度>
-
您需要提供回溯。
标签: python flask flask-mail