#8804 closed defect (fixed)
AttributeError: 'float' object has no attribute 'strip'
Reported by: | 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)
Change History (6)
comment:1 Changed 14 years ago by
Priority: | high → low |
---|---|
Severity: | major → normal |
comment:2 Changed 14 years ago by
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 follow-up: 4 Changed 14 years ago by
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 Changed 14 years ago by
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
102 102 row = {} 103 103 i = 0 104 104 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 108 117 109 118 i += 1 110 119 data.append(row)
Changed 14 years ago by
Attachment: | celltypes.xls added |
---|
comment:5 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.