2011-02-07 31 views
3

我在讀取python中的一些字符時遇到問題。UnicodeDecodeError讀取CSV中的字符串

我在UTF-8格式的csv文件,和我讀,但是當腳本閱讀:

Preußen Münster-Kaiserslautern II 

我得到這個錯誤:

Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 515, in __call__ 
    handler.get(*groups) 
    File "/Users/fermin/project/gae/cuotastats/controllers/controllers.py", line 50, in get 
    f.name = unicode(row[1]) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) 

我試圖使用Unicode函數和字符串轉換爲Unicode,但我還沒有找到解決方案。我試圖使用sys.setdefaultencoding('utf8'),但這也不起作用。

回答