使用python后台程序发送模板消息,代码如下
url = f'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={access_token}'
params = {
"touser": "oSyuJ4vOTcvx-xxxTv3mXSZ8F4GE",
"template_id":"WLSiIt0f0H5WwNILmcf3gY9aADrhjQJ1pJWaHKmz0ZA",
"data": {
"first": {
"value": "您的设备已触发温度报警"
# "color": "#173177"
}
"keyword1": {
"value": "1222032091"
# "color": "#173177"
},
"keyword2": {
"value": "温湿度恒温箱"
# "color": "#173177"
},
"keyword3": {
"value": "2021年06月07日 19:00:00"
# "color": "#173177"
},
"keyword4": {
"value": "温度超标 45°C"
# "color": "#173177"
},
"remark": {
"value": "2022-02-10 10:00:00"
# "color": "#173177"
}
}
# }
}
payl = json.dumps(params)
response = requests.post(url=url, json=payl)
response {"errcode":47001,"errmsg":"data format error rid: 620cb249-360cbce4-0dbdf1e4"}
提示格式错误。请帮助看一下问题在哪里。
你好,47001解析 JSON/XML 内容错误。请使用UTF-8编码
paylll {"touser": "oSyuJ4vOTcvx-9bmTv3mXSZ8F4GE", "template_id": "WLSiIt0f0H5WwNILmcf3gY9aADrhjQJ1pJWaHKmz0ZA", "data": {"first": {"value": "\xe6\x81\xad\xe5\x96\x9c\xe4\xbd\xa0\xe8\xb4\xad\xe4\xb9\xb0\xe6\x88\x90\xe5\x8a\x9f\xef\xbc\x81"}, "keyword1": {"value": "212134"}, "keyword2": {"value": ""}, "keyword3": {"value": ""}, "keyword4": {"value": ""}, "remark": {"value": ""}}}
返回依然是数据格式问题
response {"errcode":47001,"errmsg":"data format error rid: 620f3a38-65ad1994-5f478e77"}
发送网址:
url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + access_token
发送命令如下:
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url=url, headers=headers, data=paylll)
请求帮助解决,谢谢。
发送数据格式:
payl {"touser": "oSyuJ4vOTcvx-9bmTv3mXSZ8F4GE", "template_id": "WLSiIt0f0H5WwNILmcf3gY9aADrhjQJ1pJWaHKmz0ZA", "data": {"first": {"value": "\u60a8\u7684\u8bbe\u5907\u5df2\u89e6\u53d1\u6e29\u5ea6\u62a5\u8b66"}, "keyword1": {"value": "1222032091"}, "keyword2": {"value": "\u6e29\u6e7f\u5ea6\u6052\u6e29\u7bb1"}, "keyword3": {"value": "2021\u5e7406\u670807\u65e5 19:00:00"}, "keyword4": {"value": "\u6e29\u5ea6\u8d85\u6807 45\u00b0C"}, "remark": {"value": "2022-02-10 10:00:00"}}}