From a2bc2ef9fb6a7b471ec27dde78a314f92541c844 Mon Sep 17 00:00:00 2001 From: Janne Vanhala Date: Sat, 23 Sep 2023 18:15:20 +0300 Subject: [PATCH] Fix crash when loading databook from XLS `xlrd.open_workbook()` function expects the `file_contents` argument to be a string. Fixes #522 --- src/tablib/formats/_xls.py | 2 +- tests/test_tablib.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tablib/formats/_xls.py b/src/tablib/formats/_xls.py index 6c8dce78..2c6c5272 100644 --- a/src/tablib/formats/_xls.py +++ b/src/tablib/formats/_xls.py @@ -100,7 +100,7 @@ def import_book(cls, dbook, in_stream, headers=True): dbook.wipe() - xls_book = xlrd.open_workbook(file_contents=in_stream) + xls_book = xlrd.open_workbook(file_contents=in_stream.read()) for sheet in xls_book.sheets(): data = tablib.Dataset() diff --git a/tests/test_tablib.py b/tests/test_tablib.py index 9830d785..e783d414 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -1147,6 +1147,11 @@ def test_xls_import_with_errors(self): ]) ) + def test_book_import_from_stream(self): + in_stream = self.founders.xls + book = tablib.Databook().load(in_stream, 'xls') + self.assertEqual(book.sheets()[0].title, 'Founders') + class XLSXTests(BaseTestCase): def test_xlsx_format_detect(self):