嘗試將csv文件導入Django模型後,我不斷收到此錯誤消息。如何讀取CSV數據到Django模型?
TICKERS
有兩列:柱[0] =名,列[1] =股票
populate_symbol.py
def populate():
with open(TICKERS, 'rU') as csvfile:
file = csv.reader(csvfile, delimiter=',')
for row in file:
add_ticker(str(row[0]), str(row[1]))
def add_ticker(name, ticker):
c = Symbol.objects.get_or_create(name=name, ticker=ticker)
return c
錯誤消息:
(result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 555: invalid start byte
是否有一種方法來標誌CSV閱讀器讀取所有類型的數據(UTF-8或Unicode)的?
P.S:
的Python 3.4.3,Django的1.7