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

错误如下:

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

发送的代码如下:

def POST(self):
        data = web.data()
        reg = ''''''
        reg2 = ''
        reg3 = '(\d+)'
        reg4 = ''
        reg5 = ''
        reg6 = '(\d+)'
        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')
这一句转换,则发送中文消息时只能发一个字。超过就会包文本消息为空的错误。
 
  

你可能感兴趣的:(Python)