def sendmessage(url, msg, at_list=[]): """ 给钉钉发消息 """ HEADERS = { "Content-Type": "application/json ;charset=utf-8 " } # String_textMsg = { # "msgtype": "markdown", # "markdown": mdmsg, # "at": { # "atMobiles": at_list, # "isAtAll": 0 # 如果需要@所有人,这些写1 # } # } String_textMsg = { "msgtype": "text", "text": {"content": msg}, "at": { "atMobiles": at_list, # ["10086"] "isAtAll": 0 # 如果需要@所有人,这些写1 } } String_textMsg = json.dumps(String_textMsg) res = requests.post(url, data=String_textMsg, headers=HEADERS) print(str(datetime.datetime.now()) + " 发送钉钉消息:" + str(res.text))