Skip to content

Python 3.10 save_data to StringIO error TypeError: string argument expected, got 'bytes' #33

Closed
@ondrejkolin

Description

@ondrejkolin

Writing to memory example from the README.md doesn't work in Python3.10.

>>> from pyexcel_ods3 import save_data
>>> data = OrderedDict()
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
>>> data.update({"Sheet 2": [[7, 8, 9], [10, 11, 12]]})
>>> io = StringIO()
>>> save_data(io, data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/pyexcel_ods3/__init__.py", line 43, in save_data
    write_data(afile, data, file_type=file_type, **keywords)
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/pyexcel_io/io.py", line 142, in save_data
    with get_writer(**keywords) as writer:
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/pyexcel_io/writer.py", line 51, in __exit__
    self.close()
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/pyexcel_io/writer.py", line 45, in close
    self.writer.close()
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/pyexcel_ods3/odsw.py", line 114, in close
    self.ods_book.save()
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/ezodf/document.py", line 125, in save
    self._saving_routine()
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/ezodf/document.py", line 233, in _saving_routine
    self.filemanager.save(self.docname, backup=self.backup)
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/ezodf/filemanager.py", line 88, in save
    self._tozip(zippo)
  File "/home/ondrej/logistic/backend/venv/lib64/python3.10/site-packages/ezodf/filemanager.py", line 144, in _tozip
    zippo.writestr(mimetype.zipinfo, mimetype.tobytes())
  File "/usr/lib64/python3.10/zipfile.py", line 1814, in writestr
    with self.open(zinfo, mode='w') as dest:
  File "/usr/lib64/python3.10/zipfile.py", line 1517, in open
    return self._open_to_write(zinfo, force_zip64=force_zip64)
  File "/usr/lib64/python3.10/zipfile.py", line 1612, in _open_to_write
    self.fp.write(zinfo.FileHeader(zip64))
TypeError: string argument expected, got 'bytes'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions