有一个列表.里面有不确定的字符,直接print会报错,源码如下
#coding=utf8
import itchat, time
import sys
from itchat.content import *
@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply(msg):
print("1111")
qun=itchat.get_chatrooms()
#print(repr)
print(qun)
#itchat.dumps()
#for i in range(len(qun)):
#print (i,qun[i].decode(sys.stdin.encoding, 'replace'))
#print (i,qun[i].decode(sys.stdin.encoding, 'ignore'))
#print (i,qun[i].decode('gbk', 'ignore').encode('utf-8'))
#print (i,qun[i])
itchat.send('%s: %s' % (msg['Type'], msg['Text']), msg['FromUserName'])
itchat.auto_login(True)
itchat.run()
错误信息如下
File "test.py", line 11, in text_reply
print(qun)
UnicodeEncodeError: 'gbk' codec can't encode character '
\U0001f338' in position 2610: illegal multibyte sequence
如果我遍历列表打印的话,同样报错...问了好多人,都没问出办法....这python 不会这么坑吧?请问大神这应该怎么解决?
File "test.py", line 17, in text_reply
print (i,qun[i])
UnicodeEncodeError: 'gbk' codec can't encode character '
\U0001f338' in position 129: illegal multibyte sequence
雷雷
祝你好运!