[問題] utf8 & cp950

看板Python作者 (smigo)時間11年前 (2013/09/24 14:04), 編輯推噓0(007)
留言7則, 2人參與, 最新討論串1/2 (看更多)
程式碼: 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

09/24 22:40, , 1F
www.scarfboy.com/coding/unicode-tool?s=U%2B30fc
09/24 22:40, 1F

09/24 22:40, , 2F
這個字是「ー」,但 Big5 沒有對應
09/24 22:40, 2F

09/24 22:41, , 3F
可以用 '\u30fc'.encode('cp950', "ignore") 忽略它…
09/24 22:41, 3F

09/30 17:03, , 4F
也有可能是print的問題 試試看
09/30 17:03, 4F

09/30 17:03, , 5F
import sys,io
09/30 17:03, 5F

09/30 17:04, , 6F
sys.stdout = io.TextIOWrapper(sys.stdout.detach(),
09/30 17:04, 6F

09/30 17:04, , 7F
encoding='utf-8')
09/30 17:04, 7F
文章代碼(AID): #1IGPlrn8 (Python)
討論串 (同標題文章)
以下文章回應了本文
問題
5
5
完整討論串 (本文為第 1 之 2 篇):
問題
0
7
問題
5
5
文章代碼(AID): #1IGPlrn8 (Python)