问题描述
您的数据包含“基本多语言平面” 之外的字符。例如,表情符号位于BMP之外,IDLE Tk使用的窗口系统无法处理此类字符。
import sys
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
print(x.translate(non_bmp_map))
将non_bmp_map
BMP之外的所有代码点(任何高于0xFFFF的代码点,一直映射到您的Python版本可以处理的最高Unicode代码点)映射到U
+ FFFD REPLACEMENT CHARACTER:
>>> print('This works outside IDLE! \U0001F44D')
This works outside IDLE! 解决方法
运行Python代码时,出现以下错误:
File "E:\python343\crawler.py",line 31,in <module>
print (x1)
File "E:\python343\lib\idlelib\PyShell.py",line 1347,in write
return self.shell.write(s,self.tags)
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 1050-1050: Non-BMP character not supported in Tk
这是我的代码:
x = g.request('search',{'q' : 'TaylorSwift','type' : 'page','limit' : 100})['data'][0]['id']
# GET ALL STATUS POST ON PARTICULAR PAGE(X=PAGE ID)
for x1 in g.get_connections(x,'feed')['data']:
print (x1)
for x2 in x1:
print (x2)
if(x2[1]=='status'):
x2['message']
我怎样才能解决这个问题?