钉钉机器人-实现监控通知功能-python

1. 首先得创建有 一个 钉钉群。(因为只能发群通知)

2. 添加机器人,得到一个url: 

 

 3. 开始写Python脚本:

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 12:02:32 2018

@author: Administrator
"""
import requests

# 钉钉生成的url
url = 'https://oapi.dingtalk.com/robot/send?access_token=$$$$$$$$$$$$$$'
# 中没有headers的'User-Agent',通常会失败。
headers = {"Content-Type": "application/json ;charset=utf-8 "}

# post 发送数据格式参考:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1
# 这里使用  文本类型
data="""{
     "msgtype": "text",
     "text": {
         "content": "我就是我,  @1825718XXXX 是不一样的烟火"
     },
     "at": { 
         "isAtAll": true
     }
}
"""

r = requests.post(url, data=data.encode('utf-8'), headers=headers)
print (r.text)
原文地址:https://www.cnblogs.com/andylhc/p/9706550.html