作者sweslo17 (smigo)
看板Python
标题[问题] utf8 & cp950
时间Tue Sep 24 22:04:34 2013
程式码:
http://ideone.com/PFYV3X
使用版本是Python 3.3
在win7上执行会出现以下错误:
Traceback (most recent call last):
File "test.py", line 17, in <module>
print (response.text.encode('cp950'))
UnicodeEncodeError: 'cp950' codec can't encode character '\u30fc' in position
29222: illegal multibyte sequence
有查了一些资料 也知道是编码的问题
response.text的型态是str应该已经是utf-8
不知道为什麽还是会出现错误??
而且在这样的行况下也无法写档 一样会出现encode错误
请各位大大帮忙看看Orz.....
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 36.231.45.221
1F:→ ccwang002:www.scarfboy.com/coding/unicode-tool?s=U%2B30fc 09/24 22:40
2F:→ ccwang002:这个字是「ー」,但 Big5 没有对应 09/24 22:40
3F:→ ccwang002:可以用 '\u30fc'.encode('cp950', "ignore") 忽略它… 09/24 22:41
4F:→ talenttb:也有可能是print的问题 试试看 09/30 17:03
5F:→ talenttb:import sys,io 09/30 17:03
6F:→ talenttb:sys.stdout = io.TextIOWrapper(sys.stdout.detach(), 09/30 17:04
7F:→ talenttb: encoding='utf-8') 09/30 17:04