Modify

Opened 13 years ago

Closed 13 years ago

Last modified 9 years ago

#8804 closed defect (fixed)

AttributeError: 'float' object has no attribute 'strip'

Reported by: ruedi.silvestri@… Owned by: François Granade
Priority: low Component: TicketImportPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

I got successfully TicketImportPlugin 0.8 and xlrd 0.7.1 install. Though trying to upload a Excel 2003 format xls results to an "AttributeError: 'float' object has no attribute 'strip'" exception.

Datei "build/bdist.win32/egg/trac/web/main.py", Zeile 517, in _dispatch_request
Datei "build/bdist.win32/egg/trac/web/main.py", Zeile 238, in dispatch
Datei "build/bdist.win32/egg/talm_importer/importer.py", Zeile 77, in process_request
Datei "build/bdist.win32/egg/talm_importer/importer.py", Zeile 121, in _do_preview
Datei "build/bdist.win32/egg/talm_importer/importer.py", Zeile 348, in _process 

Attachments (1)

celltypes.xls (18.5 KB) - added by Jun Omae 13 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 13 years ago by ruedi.silvestri@…

Priority: highlow
Severity: majornormal

I just identified the issues being caused by having blanks in the file name I tried to upload. Maybe it would help to catch this exception with a respective error message as a workaround.

Thanks, Ruedi.

comment:2 Changed 13 years ago by ruedi.silvestri@…

please ignore the above comment about the filename. I managed to identify the cause which was origined by a text value in a cell which is supposed to be a number. Actually it would be good to make below extensions:

1) validate format of source value and raise exceptions if issues found. 2) pure number values seem automatically to be considered as floating numbers. Though on some reference numbers one would not want to have the number suffixed by .0 by the import.

Regards, Ruedi.

comment:3 Changed 13 years ago by François Granade

Ruedi,

Could you attach a .xls file that shows the problem to this ticket ? I don't have Excel 2003 and it will save me some time....

Thanks for reporting and for investigating !

comment:4 in reply to:  3 Changed 13 years ago by Jun Omae

I attach Excel 2003 file which contains text, number, date, boolean and error cells, celltypes.xls. When excel file has boolean and error cells other than number cells, the same issue occurs.

The following patch; convert the value to string for each cell type.

  • talm_importer/readers.py

     
    102102            row = {}
    103103            i = 0
    104104            for cx in xrange(self.sh.ncols):
    105                 row[header[i]] = self.sh.cell_value(rx, cx)
    106                 if self.sh.cell_type(rx, cx) == xlrd.XL_CELL_DATE:
    107                     row[header[i]] = datetime.datetime(*xlrd.xldate_as_tuple(row[header[i]], self.book.datemode)).strftime(self._datetime_format)
     105                val = self.sh.cell_value(rx, cx)
     106                cell_type = self.sh.cell_type(rx, cx)
     107                if cell_type == xlrd.XL_CELL_NUMBER:
     108                    val = '%g' % val
     109                elif cell_type == xlrd.XL_CELL_DATE:
     110                    val = datetime.datetime(*xlrd.xldate_as_tuple(val, self.book.datemode))
     111                    val = val.strftime(self._datetime_format)
     112                elif cell_type == xlrd.XL_CELL_BOOLEAN:
     113                    val = ('FALSE', 'TRUE')[val]
     114                elif cell_type == xlrd.XL_CELL_ERROR:
     115                    val = xlrd.error_text_from_code.get(val) or '#ERR%d' % val
     116                row[header[i]] = val
    108117
    109118                i += 1
    110119            data.append(row)

Changed 13 years ago by Jun Omae

Attachment: celltypes.xls added

comment:5 Changed 13 years ago by Jun Omae

Resolution: fixed
Status: newclosed

(In [10230]) fixed #8804, convert value of cell which is number, boolean or error cell to string.

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.