【发布时间】:2013-11-08 13:15:31
【问题描述】:
我正在通过 Django 上传文件控件读取 CSV 文件。
我想将½ (1/2) 存储到数据库中,但它给出了以下异常:
'utf8' codec can't decode byte 0xbd C.S.V. file 1/2 Char
UnicodeDecodeError at /admin/request_system/customers/upload/
'utf8' 编解码器无法解码位置 45 中的字节 0xbd:无效起始字节
【问题讨论】:
-
你能告诉我们Django视图的代码吗?您如何阅读 CSV 文件?
-
你确定是utf-8编码的吗?
-
with open(Customer.get_temp_file_name(), 'r') as data_file: reader = MyFileReader(_file=data_file) def __init__(self, _file=None): if _file: self.DATA_FILE = csv .DictReader(_file)
-
好吧,我不确定,如果它是 utf-8,因为我已经尝试了所有方法来转换 1/2,但没有任何效果
-
@Cannon:你可以edit你的问题添加细节。
标签: python python-2.7 csv unicode