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

Issue #1081 on hold
occupo
created an issue

I have a small script that opens some excel files, reads some lines and prints out what it found; nothing fancy in the excel files except some the fact that some rows are colored.

When I run the script I get this:

Traceback (most recent call last):
  File "/home/occupo/bin/eexportMajorIncidents.py", line 42, in <module>
    wb = openpyxl.load_workbook(f[1])
  File "/usr/lib/python3.6/site-packages/openpyxl/reader/excel.py", line 223, in load_workbook
    apply_stylesheet(archive, wb) # bind styles to workbook
  File "/usr/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 178, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
  File "/usr/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 100, in from_tree
    return super(Stylesheet, cls).from_tree(node)
  File "/usr/lib/python3.6/site-packages/openpyxl/descriptors/serialisable.py", line 80, in from_tree
    obj = desc.from_tree(el)
  File "/usr/lib/python3.6/site-packages/openpyxl/descriptors/sequence.py", line 86, in from_tree
    return [self.expected_type.from_tree(el) for el in node]
  File "/usr/lib/python3.6/site-packages/openpyxl/descriptors/sequence.py", line 86, in <listcomp>
    return [self.expected_type.from_tree(el) for el in node]
  File "/usr/lib/python3.6/site-packages/openpyxl/styles/fills.py", line 64, in from_tree
    return PatternFill._from_tree(child)
  File "/usr/lib/python3.6/site-packages/openpyxl/styles/fills.py", line 102, in _from_tree
    return cls(**attrib)
TypeError: __init__() got an unexpected keyword argument 'extLst'

I found this issue #928 with this commit and I can confirm i have the line in "/usr/lib/python3.6/site-packages/openpyxl/pivot/table.py".

I managed to fix it by editing "/usr/lib/python3.6/site-packages/openpyxl/styles/fills.py" like this:

BEFORE (lines 84 and 85) :

   def __init__(self, patternType=None, fgColor=Color(), bgColor=Color(),
                 fill_type=None, start_color=None, end_color=None):

AFTER (same lines):

   def __init__(self, patternType=None, fgColor=Color(), bgColor=Color(),
                 fill_type=None, start_color=None, end_color=None, **extLst=None**):

Let me know if you need any other info or if I can help in some way.

Thanks.

Comments (23)

  1. occupo reporter

    after the change, I also get this:

    /usr/lib/python3.6/site-packages/openpyxl/reader/worksheet.py:320: UserWarning: Unknown extension is not supported and will be removed warn(msg)

    This is the portion of the file:

       def parse_extensions(self, element):
            extLst = ExtensionList.from_tree(element)
            for e in extLst.ext:
                ext_type = EXT_TYPES.get(e.uri.upper(), "Unknown")
                msg = "{0} extension is not supported and will be removed".format(ext_type)
                warn(msg)
    

    If I comment the last line everything is ok. I know it's only a warning but I see it's also related to extLst.

  2. occupo reporter

    can you please tell me how I can do that? I don't have a lot of experience either with these processes (or at all). thank you.

  3. occupo reporter

    I upgraded openpyxl to 2.5.5:

    pip list

    Package Version


    openpyxl 2.5.5

    I get the same error:

    Traceback (most recent call last):
      File "bin/eexportMajorIncidents.py", line 41, in <module>
        wb = openpyxl.load_workbook(f[1])
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/reader/excel.py", line 224, in load_workbook
        apply_stylesheet(archive, wb) # bind styles to workbook
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 178, in apply_stylesheet
        stylesheet = Stylesheet.from_tree(node)
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/styles/stylesheet.py", line 100, in from_tree
        return super(Stylesheet, cls).from_tree(node)
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/descriptors/serialisable.py", line 80, in from_tree
        obj = desc.from_tree(el)
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/descriptors/sequence.py", line 86, in from_tree
        return [self.expected_type.from_tree(el) for el in node]
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/descriptors/sequence.py", line 86, in <listcomp>
        return [self.expected_type.from_tree(el) for el in node]
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/styles/fills.py", line 64, in from_tree
        return PatternFill._from_tree(child)
      File "/home/occupo/.venvs/myP/lib/python3.6/site-packages/openpyxl/styles/fills.py", line 102, in _from_tree
        return cls(**attrib)
    TypeError: __init__() got an unexpected keyword argument 'extLst'
    
  4. CharlieC

    I cannot replicate the error using the file provided. Neither Gradient nor Pattern fill elements can have extensions, though this is where the problem is occurring according to the original traceback. The stylesheet of the file provided also does not have extensions in the fills and does also not have any pivot tables, which is what the commt you mention deals with.

  5. occupo reporter

    so what happens now? do you need any more info? or should I just freeze my openpyxl version with the modified files and leave it like this?

  6. occupo reporter

    hi. I rewrote parts of the script and started to run it on different files that it was reading; I identified this warning from libreoffice calc for some files; these are the same files that crash openpyxl. I attached a screenshot.

    libreoffice_calc_warning.png

  7. CharlieC

    I don't think that screenshot is relevant here. As I cannot reproduce the problem you see with the file supplied the issue has to stay on hold.

  8. occupo reporter

    problem cannot be reproduced; I have a file that generates the error but it contains sensitive data; when I manage to recreate another file with the same symptoms I will upload it.

  9. Matthias Berg

    I get the same error with this code and the attached xlsx (freeoffice). openpyxl 2.6.1. If I open the file in MS Excel and save it, it gets 3bytes bigger and it works without exception. So I assume the FreeOffice file isnt as compatible as I hoped. Additionally I tried uploading the freeoffice file to google sheets and downloaded from tehre as ms excel file and I get a compatible file that works.

    from openpyxl import load_workbook
    wb = load_workbook('test.xlsx')
    
  10. Matthias Berg

    I can see that this is the problem. I also don't really care or need this bug to be fixed. Actually it's not really a bug, but it could be an improvement ticket. Apparently MS Excel and Google Sheets are able to work with those files, so in order to improve compatibility, you could ignore the extensions where none are allowed, instead of throwing an exception. FreeOffice and LibreOffice are still not as widespread, but I think you could improve the openpyxl project by trying to work with those files as well.

  11. CharlieC

    openpyxl tries to be compatible with the published standard. Compatibility is improved when all applications and libraries follow the standard. Adding workarounds for bugs in other applications (in this case invalid OOXML) does not improve compatbility. You should really report the bug to Softmaker.

  12. Log in to comment