Modify

Opened 3 years ago

Closed 2 years ago

#9730 closed defect (fixed)

"AttributeError: 'list' object has no attribute 'decode'"

Reported by: snoopotic Owned by: farialima
Priority: normal Component: TicketImportPlugin
Severity: normal Keywords:
Cc: jun66j5 Trac Release: 0.12

Description

Hi,
trying to import a csv or something else errors at:

2012-01-26 10:16:28,645 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/Trac-0.12.2-py2.6.egg/trac/web/main.py", line 511, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.6/site-packages/Trac-0.12.2-py2.6.egg/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 77, in process_request
    encoding=req.session['importer.encoding'])
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 121, in _do_preview
    return self._process(filereader, get_reporter_id(req), PreviewProcessor(self.env, req))
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/importer.py", line 317, in _process
    for row in rows:
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 60, in next
    return dict((_to_unicode(key), _to_unicode(val)) for key, val in d.iteritems())
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 60, in <genexpr>
    return dict((_to_unicode(key), _to_unicode(val)) for key, val in d.iteritems())
  File "/usr/lib/python2.6/site-packages/TicketImport-0.8-py2.6.egg/talm_importer/readers.py", line 45, in _to_unicode
    return val.decode('utf-8')
AttributeError: 'list' object has no attribute 'decode'

But I also possibly found the solution:
Change in readers.py (of ver. 0.8.2):

 42 def _to_unicode(val):
 43     if val is None or isinstance(val, unicode):
 44         return val
 45     return val.decode('utf-8')

to:

 42 def _to_unicode(val):
 43     if val is None or isinstance(val, unicode):
 44         return val[0]
 45     return val[0].decode('utf-8')

Attachments (2)

Anf_test_OK.csv (409 bytes) - added by snoopotic 3 years ago.
csv that is ok
Anf_test_NOTOK.csv (429 bytes) - added by snoopotic 3 years ago.
csv that is not ok

Download all attachments as: .zip

Change History (7)

comment:1 Changed 3 years ago by farialima

Hello snoopotic - could you attach a .csv file that exposes the problem ? I'd love to take your patch but would like to add a testcase too..

comment:2 Changed 3 years ago by snoopotic

sorry, I think this case can be closed as wontfix:
The CSV we used had errors:
first line was defining the fields with 5 separations but some lines beneath the "description" part contained also some ";" (semicolon) that were interpreted as separators and this error appeared.
I attached the csvs.
Maybe there can be implemented an improvement not to throw that Exception but a Warning that the csv is nod valid - so you know to look into the csv.

btw: with my change you don't get this warning but also the valid one does not work :/

Sorry for that.

Changed 3 years ago by snoopotic

csv that is ok

Changed 3 years ago by snoopotic

csv that is not ok

comment:3 Changed 3 years ago by jun66j5

(In [11210]) Ignores more field values than the field names (refs #9730).

comment:4 Changed 3 years ago by jun66j5

  • Cc jun66j5 added

Hi snoopotic,

I can reproduce the issue when a row has more fields than the field names. In [11210], ignores simply the values. Please try the latest if you can. Thanks.

comment:5 Changed 2 years ago by jun66j5

  • Resolution set to fixed
  • Status changed from new to closed

Already fixed

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.