关于发送微信客服消息报44004错误的解决办法

本文介绍了一种解决微信API在发送包含中文的消息时出现的错误方法。通过将发送的消息内容转换为UTF-8编码,成功实现了完整中文消息的发送。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误如下:

{"errcode":44004,"errmsg":"empty content hint: [xCzlfa0209ge25]"} 

发送的代码如下:

def POST(self):
        data = web.data()
        reg = '''<xml><ToUserName><!\[CDATA\[(.*?)\]\]></ToUserName>'''
        reg2 = '<FromUserName><!\[CDATA\[(.*?)\]\]></FromUserName>'
        reg3 = '<CreateTime>(\d+)</CreateTime>'
        reg4 = '<MsgType><!\[CDATA\[(.*?)\]\]></MsgType>'
        reg5 = '<Content><!\[CDATA\[(.*?)\]\]></Content>'
        reg6 = '<MsgId>(\d+)</MsgId>'
        fromusers = re.compile(reg2).findall(data)[0]
        MsgType = re.compile(reg4).findall(data)[0]
        Content = re.compile(reg5).findall(data)[0]
        username, city = self.get_userinfo(fromusers)
        if fromusers != 'owV3nvshcqIgwflEMlikiXdwaP7M':
            self.leandbs.save_userinfo(fromusers)
            dic = {"touser":"owV3nvshcqIgwflEMlikiXdwaP7M","msgtype":"text","text":{"content":'【%s %s】:%s' % (city, username ,Content)}}    
        else:
            fromuser = self.leandbs.select_userinfo('key','1','openid')
            dic = {"touser":fromuser,"msgtype":"text","text":{"content":Content}}    
        dics = json.dumps(dic,ensure_ascii=False)
        dics = dics.encode('utf-8')
        url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s' % self.get_token()
        result = requests.post(url,data=dics)
        print result.content
        return 'success'

如果不加
dics = dics.encode('utf-8')
这一句转换,则发送中文消息时只能发一个字。超过就会包文本消息为空的错误。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值