TypeError: __init__() got an unexpected keyword argument 'and'

Issue #780 resolved
Mark Charney created an issue

I just tried openpyxl to see if would work with my large (2MB) xlsxf file and it failed as follows. I cannot supply the xlsx file as it contains sensitive data for my job.

% pip install openpyxl
Collecting openpyxl
  Downloading openpyxl-2.4.5.tar.gz (180kB)
    100% |################################| 184kB 779kB/s 
Collecting jdcal (from openpyxl)
  Downloading jdcal-1.3.tar.gz
Collecting et_xmlfile (from openpyxl)
  Downloading et_xmlfile-1.0.1.tar.gz
Installing collected packages: jdcal, et-xmlfile, openpyxl
  Running setup.py install for jdcal ... done
  Running setup.py install for et-xmlfile ... done
  Running setup.py install for openpyxl ... done
Successfully installed et-xmlfile-1.0.1 jdcal-1.3 openpyxl-2.4.5

% python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openpyxl
>>> wb = openpyxl.load_workbook('vm-sharing/test.xlsx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/reader/excel.py", line 238, in load_workbook
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/reader/worksheet.py", line 129, in parse
    obj = prop[1].from_tree(element)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/descriptors/serialisable.py", line 76, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/descriptors/serialisable.py", line 76, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/descriptors/serialisable.py", line 89, in from_tree
    return cls(**attrib)
TypeError: __init__() got an unexpected keyword argument 'and'

Comments (16)

  1. CharlieC

    Can't really do much without the file but the exception is coming from the properties of one of the worksheets – should't have any sensitive data in them. You should be able to write a test case by looking at how these tags are parsed.

            properties = {
                '{%s}printOptions' % SHEET_MAIN_NS: ('print_options', PrintOptions),
                '{%s}pageMargins' % SHEET_MAIN_NS: ('page_margins', PageMargins),
                '{%s}pageSetup' % SHEET_MAIN_NS: ('page_setup', PrintPageSetup),
                '{%s}headerFooter' % SHEET_MAIN_NS: ('HeaderFooter', HeaderFooter),
                '{%s}autoFilter' % SHEET_MAIN_NS: ('auto_filter', AutoFilter),
                '{%s}dataValidations' % SHEET_MAIN_NS: ('data_validations', DataValidationList),
                '{%s}sortState' % SHEET_MAIN_NS: ('sort_state', SortState),
                '{%s}sheetPr' % SHEET_MAIN_NS: ('sheet_properties', WorksheetProperties),
                '{%s}sheetViews' % SHEET_MAIN_NS: ('views', SheetViewList),
                '{%s}sheetFormatPr' % SHEET_MAIN_NS: ('sheet_format', SheetFormatProperties)
  2. Mark Charney reporter

    Thanks. Can you give me some context as to what you want me to do with the above code?

  3. Mark Charney reporter

    Actually, you can close this. I deleted a bunch of tabs for stuff I was not using and the problem appears to have gone away.

  4. CharlieC

    You can close the bug yourself if you like, though it would be nice to know what's causing it. The code is from the WorksheetParser class and has all the tags that are processed by the code in your exception. One of the worksheets that you deleted has some definition that we can't parse properly.

  5. Mark Charney reporter

    I'll see if I have time to reduce the test case.

    Aside: "openpyxl never evaluates formula but it is possible to check the name of a formula" So if I have heavy duty formulas in my spreadsheet, I cannot get the resulting values from openpyxl?

  6. CharlieC

    To find the relevant XML you should unzip the XLSX file and search the files called sheet*.xml for text like and="

  7. CharlieC

    Regarding formulae: if the file was created by something like Excel then you can use data-only mode to extract the last calculated value for a formula. The formula, is of course, lost.

  8. Mark Charney reporter

    regarding formulae: thanks!! that's super. (you might want to make that factoid more prominent in the documentation/examples)

  9. CharlieC

    Looks like this was related to the use of custom filters. Should be fixed now. Would be nice if you test it with a checkout.

  10. Nnamdi Kohn

    Didn't want to offend anybody by duplicating this issue here. As this one has the status of "resolved", I thought, maybe there was nobody checking for new comments on this issue #780. That's why I created a "visible" one. Just to see that it was dismissed as "duplocate"...

    Anyway, as I still hope for some hints to resolve my issue #784, I'd be glad if a developer could pick me up again. I guess, in order to test the recent package version, I would have to build from source... hope to be able to figure out, how, until the weekend.


  11. Log in to comment