And*_*di 11 python unicode encoding ucs2
当我运行我的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
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
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']
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
Mar*_*ers 26
您的数据包含基本多语言平面之外的字符.例如,表情符号在BMP之外,IDLE,Tk使用的窗口系统无法处理这些字符.
import sys
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
print(x.translate(non_bmp_map))
Run Code Online (Sandbox Code Playgroud)
该non_bmp_map
(代码点任何超过0xFFFF的更高,达到了所有的方式映射所有的码点的BMP之外最高的Unicode编码点你的Python版本可以处理)到U + FFFD替换字符:
>>> print('This works outside IDLE! \U0001F44D')
This works outside IDLE!
>>> print('This works in IDLE too! \U0001F44D'.translate(non_bmp_map))
This works in IDLE too! ?
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
25898 次 |
最近记录: |