通过钉钉发送报警信息

1,网友的

import json,requests 
def info():
  url = 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxx'
  headers = { 'Content-Type': 'application/json;charset=utf-8' }
  formdata = { "msgtype": "text", "text": {"content":str('测试钉钉')} }
  hhh = requests.post(url=url, data=json.dumps(formdata), headers=headers)
  print hhh.text if __name__ == '__main__':
  info()

2,实际使用的:

import json,requests
def
Alert(msg): headers = {"Content-Type": "application/json"} data = {"msgtype": "text", "text": {"content": msg}} r = requests.post( "https://oapi.dingtalk.com/robot/send?access_token= xxx ", data=json.dumps(data), headers=headers)
Alert(msg)

猜你喜欢

转载自www.cnblogs.com/kaishirenshi/p/10478383.html