企业微信机器人python脚本执行报错-‘errcode‘: 40008, ‘errmsg‘: ‘Warning: wrong json format. invalid message type

错误内容

{‘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脚本调用群企业微信机器人将告警信息发送至“企业微信”群中,并@指定人员(提醒指定人员查看)

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值