由于编码错误,无法迭代CSV读取器对象

2024-05-14 18:36:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用一个第三方API,它将数据作为Python CSV读取器对象返回。你知道吗

响应CSV读取器对象如下所示:

dir(data)
Out[67]: 
['__class__',
'__delattr__',
'__doc__',
'__format__',
'__getattribute__',
'__hash__',
'__init__',
'__iter__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'dialect',
'line_num',
'next']

type(data)
Out[68]: _csv.reader

当我尝试读取此对象时,出现以下错误:

l = list(data)
Traceback (most recent call last):

File "<ipython-input-69-587d9010ea41>", line 1, in <module>
l = list(data)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 88: ordinal not in range(128)

这是我能从我这边解决的问题还是我必须让供应商来解决?你知道吗

谢谢你!你知道吗


Tags: csv数据对象inapireducedatadoc

热门问题