错误内容
{‘errcode’: 40008, ‘errmsg’: ‘Warning: wrong json format. invalid message type, hint: [1596176563_47_d9bbe040d5a640ea75f8625e35783c76], from ip: 61.183.117.38, more info at https://open.work.weixin.qq.com/devtool/query?e=40008’}
查看官网错误代码意义
40008 不合法的msgtype参数 合法的msgtype取值,参考:消息类型
原因
企业微信群机器人的消息虽然是“text”类型的,但是post发送过去的头部是“application/json”,是json格式的,查看python的request中的post方法:
def post(url, data=None, json=None, **kwargs):
r"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
"""
return request('post', url, data=data, json=json, **kwargs)
所以在python 的request中,不能使用data,data的数据只能是字典,列表或者元组。
而json= 发送的是json的数据,所以这里需要使用json
requests.post(url=URL, headers=HEADERS, json=Data, verify=False)
附链接:
Zabbix Basic -zabbix 使用python脚本调用群企业微信机器人将告警信息发送至“企业微信”群中,并@指定人员(提醒指定人员查看)