Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.5.8 specifc error when saving data to xlsx: StopIteration #37

Open
KerstenBreuer opened this issue Jan 4, 2020 · 5 comments
Open

Comments

@KerstenBreuer
Copy link

I encountered an error when writing to xlsx with the latest version 0.5.8. In the previous version, everything works fine.

When executing following example:

from pyexcel import Book, get_book
test = {
    'Sheet 1':
        [
            [1.0, 2.0, 3.0],
            [4.0, 5.0, 6.0],
            [7.0, 8.0, 9.0]
        ]
}

book = get_book(bookdict=test)
book.save_as("test.xlsx")

I receive:

Traceback (most recent call last):
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\io.py", line 148, in store_data       
    writer.write(data)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\book.py", line 220, in write
    sheet_writer.write_array(incoming_dict[sheet_name])
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\sheet.py", line 174, in write_array   
    self.write_row(row)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_xlsx\xlsxw.py", line 29, in write_row    
    self._native_sheet.append(array)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_write_only.py", line 113, in 
append
    self._get_writer()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_write_only.py", line 82, in _get_writer
    self._writer.write_top()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_writer.py", line 98, in write_top
    self.write_properties()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_writer.py", line 60, in write_properties
    self.xf.send(props.to_tree())
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_writer.py", line 294, in get_stream
    xf.write(el)
  File "src\lxml\serializer.pxi", line 1652, in lxml.etree._IncrementalFileWriter.write
TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel\internal\meta.py", line 327, in save_as  
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel\internal\core.py", line 56, in save_book 
    return _save_any(a_source, book)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel\internal\core.py", line 60, in _save_any 
    a_source.write_data(instance)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel\plugins\sources\file_output.py", line 44, in write_data
    self._file_name, book, **self._keywords
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel\plugins\renderers\excel.py", line 31, in 
render_book_to_file
    save_data(file_name, book.to_dict(), **keywords)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\io.py", line 131, in save_data        
    **keywords
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\io.py", line 148, in store_data       
    writer.write(data)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_io\book.py", line 57, in __exit__        
    self.close()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyexcel_xlsx\xlsxw.py", line 55, in close        
    self._native_book.save(filename=self._file_alike_object)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\workbook\workbook.py", line 408, in save
    save_workbook(self, filename)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook
    writer.save()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\writer\excel.py", line 275, in save     
    self.write_data()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\writer\excel.py", line 75, in write_data
    self._write_worksheets()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\writer\excel.py", line 215, in _write_worksheets
    self.write_worksheet(ws)
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\writer\excel.py", line 196, in write_worksheet
    ws.close()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_write_only.py", line 92, in close
    self._writer.write_rows()
  File "C:\Users\kerst\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\worksheet\_writer.py", line 120, in write_rows
    xf = self.xf.send(True)
StopIteration

It would be very important for us to fix this issue. Thanks a lot and best wishes

KerstenBreuer added a commit to workflux/workflUX that referenced this issue Jan 4, 2020
@chfw
Copy link
Member

chfw commented Jan 4, 2020

I will have a look!

@KerstenBreuer
Copy link
Author

Thanks a lot

@chfw
Copy link
Member

chfw commented Jan 5, 2020

Just an update.

I have tried your script on my Mac and I could not reproduced your exception.

Here is my evaluation package setup:

et-xmlfile==1.0.1
jdcal==1.4.1
lml==0.0.9
openpyxl==3.0.2
pyexcel==0.5.15
pyexcel-io==0.5.20
pyexcel-xlsx==0.5.8
texttable==1.6.2

and I have tried openpyxl 2.6.1 too.

I need to find a Windows computer to try.

@chfw
Copy link
Member

chfw commented Jan 5, 2020

Look into your exception, it was thrown out from lxml. I knew openpyxl uses lxml for performance speedup. could you please list your openpyxl version and lxml version?

@KerstenBreuer
Copy link
Author

Thanks for the fast reply.

My setup is the following:

openpyxl==3.0.2
lxml==4.4.2

I've been experiencing this issue on python3.7 on Windows as well as python3.6 on Ubuntu (running as WSL on Windows).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants