背景描述

运行 python 测试用例的过程中经常遇到下面的错误提示: 'gbk' codec can't encode character '\U0001f6d1' in position 24033: illegal multibyte sequence

解决方案

# -*- coding:utf-8 -*-
print(v.encode('utf-8'))
print(v.encode('gbk','ignore'))
print(v.encode('utf-8').decode('utf-8'))
print(v.encode('utf-8').decode('utf-8').encode('gbk','ignore').decode('gbk'))


↙↙↙阅读原文可查看相关链接,并与作者交流