from urllib import requestimport jsondef DingDing(msg): #https://oapi.dingtalk.com/robot/send?access_token=2eb3102a6fec5488d72d130781d4da6b1e1f9076838849eb04198bd55040ca5e 弹性报税后台服务告警群 url='https://oapi.dingtalk.com/robot/send?access_token=99985cc4dd60211d42b8844314b552fe5048f19a7c97a4931567aa7457b50ffb' headers = {'Content-Type': 'application/json'} #data = {"msgtype": "text", "text": {"content": msg}} # data = {"msgtype": "text", "text": {"content": msg},'isAtAll':True} #data = {"msgtype": "text", "text": {"content": msg}, "at": {"atMobiles": ["18912946489"], "isAtAll": False}} data = {"msgtype": "text", "text": {"content": "%s\n脚本路径:%s" % (msg,os.path.realpath(__file__))}, "at": {"atMobiles": ["18912946489"], "isAtAll": False}} req = request.Request(url=url,data=json.dumps(data).encode("utf-8"),headers=headers,method='POST') response = request.urlopen(req) print(response.read().decode())