【发布时间】:2021-10-20 07:21:16
【问题描述】:
我正在使用 html 电子邮件和 .format() 作为字符串传递参数
下面是我的python代码:
import sys
try:
print(5 / 0)
except Exception as e:
send_error_email(exp_message=format_exc())
然后获取函数 send_error_email 并传递给 MIMEMultipart 邮件脚本
html = """
<html>
<body>
<b> Exception Details: </b> {exp_message}
</body>
</html>
""".format(exp_message=exp_message)
在邮件中的一行中获取输出:
异常数据:回溯(最近一次调用最后一次):文件“C:\Build\test\workfile\python-practice\exception_test.py”,第 54 行,在 get_details print(100/0) ZeroDivisionError: 除以零
预期输出应该是新行中的每条消息:
异常数据:回溯(最后一次调用):
文件“C:\Build\test\workfile\python-practice\exception_test.py”,第 54 行,
在 get_details 打印(100/0)
ZeroDivisionError:整数除法或除以零
【问题讨论】:
-
@enzo 你的意思是 send_error_email(exp_message='
'.join(format_exc().splitlines()))
标签: python