zabbix 钉钉机器人报警 提示错误
执行脚本./dd.py test test test报错如下:
Traceback (most recent call last):
File "./dd.py", line 4, in
import requests
File "/usr/lib/python2.7/site-packages/requests/init.py", line 133, in
from . import utils
File "/usr/lib/python2.7/site-packages/requests/utils.py", line 27, in
from . import certs
File "/usr/lib/python2.7/site-packages/requests/certs.py", line 15, in
from certifi import where
File "/usr/lib/python2.7/site-packages/certifi/init.py", line 1, in
from .core import contents, where
File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17
def where() -> str:
^
SyntaxError: invalid syntax
脚本内容网络搜索的大致如下
#!/usr/bin/python
#coding:utf-8
import requests
import json
import sys
import os
import time
headers = {'Content-Type':'application/json;charset=utf-8'}
time=time.strftime("%Y-%m-%d %H:%M%S",time.localtime())
log_file = "var/log/dingding.log"
api_url = "我的机器人地址"
def log(info):
if os.path.isfile(log_file) == False:
f = open(log_file,'a+')
f = open(log_file,'a+')
f.write(info)
f.close()
def msg(text,user):
json_text={
"msgtype":"markdown",
"markdown":{
"title":"Winy Frist test6.6",
"text":text
},
"at":{
"atMobiles":[
user
],
"isAtAll":True
}
}
r= requests.post(api_url,data=json.dumps(json_text),headers=headers).json()
code = r["errcode"]
if code == 0:
log(time + ":消息发送成功 返回码:" + str(code) + "\n")
else:
log(time + ":消息发送失败 返回码:" + str(code) + "\n")
exit(3)
if __name__ == '__Main__':
text = sys.argv[3]
user = sys.argv[1]
msg(text,user)
请大神指点一二,错误在哪里。