Input strings must be a multiple of 16 in length

在实现微信企业号自建应用与自由服务器信息交互的时候, 报了 Input strings must be a multiple of 16 in length 这个错误, 回复全部英文内容给微信的时候是正常的.

1
2
3
4
5
6
7
sRespData = """<xml>
<ToUserName><![CDATA["""+user_id+"""]]></ToUserName>
<FromUserName><![CDATA["""+corp_id+"""]]></FromUserName>
<CreateTime>"""+create_time+"""</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA["""+content+"""]]></Content>
</xml>"""

如以上即将回复给微信的xml信息, content变量就是实际的消息内容, 当content内容出现中文字符时, 就会报以上错误.

解决方法:

content = content.encode('utf-8')

将content的内容以utf8字符编码进行encode即可