From ec6f3098bb74f9ce0917bf5fa86a57e7af657a29 Mon Sep 17 00:00:00 2001 From: ning1875 <907974064@qq.com> Date: Tue, 27 Jul 2021 11:38:42 +0800 Subject: [PATCH] notify.py add sys.encoding to avoid coding error (#744) --- etc/script/notify.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/script/notify.py b/etc/script/notify.py index 9cb37f3b..9fb2651b 100755 --- a/etc/script/notify.py +++ b/etc/script/notify.py @@ -9,6 +9,11 @@ import requests from email.mime.text import MIMEText from email.header import Header +import sys +reload(sys) # reload 才能调用 setdefaultencoding 方法 +sys.setdefaultencoding('utf-8') # 设置 'utf-8' +# 建议使用python3运行,避免python2的编码问题 + # 希望的demo实现效果: # 1. 从stdin拿到告警信息之后,格式化为一个有缩进的json写入一个临时文件 # 2. 文件路径和名字是.alerts/${timestamp}_${ruleid}