Modify

Opened 12 years ago

Closed 12 years ago

Last modified 7 years ago

#9730 closed defect (fixed)

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

Reported by: Felix Owned by: François Granade
Priority: normal Component: TicketImportPlugin
Severity: normal Keywords:
Cc: Jun Omae 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 Felix 12 years ago.
csv that is ok
Anf_test_NOTOK.csv (429 bytes) - added by Felix 12 years ago.
csv that is not ok

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by François Granade

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 12 years ago by Felix

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 12 years ago by Felix

Attachment: Anf_test_OK.csv added

csv that is ok

Changed 12 years ago by Felix

Attachment: Anf_test_NOTOK.csv added

csv that is not ok

comment:3 Changed 12 years ago by Jun Omae

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

comment:4 Changed 12 years ago by Jun Omae

Cc: Jun Omae added; anonymous removed

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 12 years ago by Jun Omae

Resolution: fixed
Status: newclosed

Already fixed

comment:6 Changed 7 years ago by huang_9119596@…

 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')

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

have other question,to link https://pdf-lib.org/Home/Details/1098

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain François Granade.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.