代码:
try:
json_data = urllib.request.Request(query)
print(type(json_data))
with urllib.request.urlopen(json_data) as data:
data1 = str(data.read().decode('utf-8'))
print(type(data1))
except Exception as e:
print ("! Sorry, something went wrong:")
print ("! Error: %s"%e)
sys.exit(1)
statuses = json.loads(data1).get("statuses")
texts = [tweet.get("text") for tweet in statuses]
for text in texts:
print (text,"\n")
错误打印:
'UCS-2' codec can't encode characters in position 227-227:
Non-BMP character not supported in Tk.
有没有办法忽略错误并继续或用替换字符替换不支持的代码?
提前致谢。