如何使用Flask设置500个错误的电子邮件警报



我正在使用flask、棉花糖和sql alchemy来制作API。我想配置500个错误的电子邮件警报。其他错误类型我有电子邮件警报工作正常。

错误处理代码

@app.errorhandler(ValidationError)
def handle_marshmallow_validation(err):  # except ValidationError as err
return jsonify(err.messages), 400
@app.errorhandler(500)
def server_error(e):
if e == 500:
error_500_email()

500错误处理程序中调用的函数:

def error_500_email():
s = smtplib.SMTP(host='mailo2.uhc.com', port=25)
text = "There was an error"
msg = MIMEText(str(text))
msg['Subject'] = 'Prod SA Tool Error'
s.sendmail('sa_prod@optum.com', 'ian.christ@optum.com', msg.as_string())
s.quit()

我怀疑e == 500条件总是计算为False,即使在500错误的情况下也是如此。

你可以修复它,但为什么不删除它呢?如果用@app.errorhandler(500)修饰处理程序,那么这个测试的目的是什么?

最新更新