看板 Python 關於我們 聯絡資訊
程式碼: 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
ccwang002:www.scarfboy.com/coding/unicode-tool?s=U%2B30fc 09/24 22:40
ccwang002:這個字是「ー」,但 Big5 沒有對應 09/24 22:40
ccwang002:可以用 '\u30fc'.encode('cp950', "ignore") 忽略它… 09/24 22:41
talenttb:也有可能是print的問題 試試看 09/30 17:03
talenttb:import sys,io 09/30 17:03
talenttb:sys.stdout = io.TextIOWrapper(sys.stdout.detach(), 09/30 17:04
talenttb: encoding='utf-8') 09/30 17:04