Closed
Description
After updating pyexcel-io I discovered this bug when intentionally passing an unsupported filetype in one of my unittests.
When passing the unsupported filetype into get_book the expected exception in the past would have been one of (FileTypeNotSupported, NoSupportingPluginFound, SupportingPluginAvailableButNotInstalled) however in book.py::_convert_content_to_stream (line 231) the call to manager.get_io (line 232) results in None causing the write method to be called on a NoneType (line 244) resulting in a generic attribute error.
def _convert_content_to_stream(file_content, file_type):
stream = manager.get_io(file_type)
target_content_type = manager.get_io_type(file_type)
needs_encode = target_content_type == "bytes" and not isinstance(
file_content, bytes
)
needs_decode = target_content_type == "string" and isinstance(
file_content, bytes
)
if needs_encode:
file_content = file_content.encode("utf-8")
elif needs_decode:
file_content = file_content.decode("utf-8")
stream.write(file_content)
stream.seek(0)
return stream
.venv/lib/python3.6/site-packages/pyexcel/core.py:47: in get_book
book_stream = sources.get_book_stream(**keywords)
.venv/lib/python3.6/site-packages/pyexcel/internal/core.py:39: in get_book_stream
sheets = a_source.get_data()
.venv/lib/python3.6/site-packages/pyexcel/plugins/sources/memory_input.py:41: in get_data
self.__file_content, **self._keywords
.venv/lib/python3.6/site-packages/pyexcel/plugins/parsers/excel.py:28: in parse_file_content
file_content, file_type=self._file_type, **keywords
.venv/lib/python3.6/site-packages/pyexcel/plugins/parsers/excel.py:40: in _parse_any
sheets = get_data(anything, file_type=file_type, **keywords)
.venv/lib/python3.6/site-packages/pyexcel_io/io.py:87: in get_data
afile, file_type=file_type, streaming=False, **keywords
.venv/lib/python3.6/site-packages/pyexcel_io/io.py:105: in _get_data
return load_data(**keywords)
.venv/lib/python3.6/site-packages/pyexcel_io/io.py:193: in load_data
reader.open_content(file_content, **keywords)
.venv/lib/python3.6/site-packages/pyexcel_io/reader.py:70: in open_content
file_content, self.file_type
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
file_content = 'foo-bar-data', file_type = 'ods'
def _convert_content_to_stream(file_content, file_type):
stream = manager.get_io(file_type)
target_content_type = manager.get_io_type(file_type)
needs_encode = target_content_type == "bytes" and not isinstance(
file_content, bytes
)
needs_decode = target_content_type == "string" and isinstance(
file_content, bytes
)
if needs_encode:
file_content = file_content.encode("utf-8")
elif needs_decode:
file_content = file_content.decode("utf-8")
> stream.write(file_content)
E AttributeError: 'NoneType' object has no attribute 'write'
.venv/lib/python3.6/site-packages/pyexcel_io/book.py:244: AttributeError
pyexcel version info
pyexcel 0.6.5
pyexcel-io 0.6.2
pyexcel-xls 0.5.8
pyexcel-xlsx 0.5.7
Metadata
Metadata
Assignees
Labels
No labels