python 调用钉钉机器人的方法

以text格式的消息为例:(只需修改content后的内容)

Import json
Import requests


url='https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxx'

HEADERS={"Content-Type":"application/json;charset=utf-8"}

String_textMsg={"msgtype":"text","text":{"content":'kind:%s\naverage:%f\nmedian:%f\nQ10:%f\nQ90:%f'%("Trans",average,median,Q10,Q90)}}

String_textMsg=json.dumps(String_textMsg)

res=requests.post(url,data=String_textMsg,headers=HEADERS)

print(res.text)

相关推荐