valq7711 / ombott

This is bottle spin-off (One More BOTTle)
MIT License
8 stars 5 forks source link

TypeError on ombott.request_pkg.multipart.BytesIOProxy object #14

Open biffyw opened 3 months ago

biffyw commented 3 months ago

The object being passed to ExcelReader is an ombott.request_pkg.multipart.BytesIOProxy object.
I'm using py4web 1.20240602.1 with openpxyl 3.1.4 and ombott 2.0 My same code works fine with py4web 1.20230528.1, openpyxl 3.1.2 and ombott 1.0.0 but I can see a lot changed... In both cases, interpreter is python 3.9.2 in separate virtual environments on Windows 10 Pro Build 19045

Happy to provide any additional details, thanks in advance.

Traceback (most recent call last):
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/py4web/core.py", line 1040, in wrapper
    ret = func(*func_args, **func_kwargs)
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/py4web/core.py", line 1025, in wrapper
    raise exception
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/py4web/core.py", line 1001, in wrapper
    context["output"] = func(*args, **kwargs)
  File "/home/biff/projects/py4web_20240530/apps/test1/controllers.py", line 228, in import_adp
    error, new, no_longer_supported = import_product_manual(path, category)
  File "/home/biff/projects/py4web_20240530/apps/test1/device_utils.py", line 26, in import_product_manual
    devices_book = load_workbook(file_object.file, read_only=True)
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 346, in load_workbook
    reader = ExcelReader(filename, read_only, keep_vba,
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 123, in __init__
    self.archive = _validate_archive(fn)
  File "/home/biff/projects/py4web_20240530/venv/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 95, in _validate_archive
    archive = ZipFile(filename, 'r')
  File "/usr/lib/python3.9/zipfile.py", line 1257, in __init__
    self._RealGetContents()
  File "/usr/lib/python3.9/zipfile.py", line 1320, in _RealGetContents
    endrec = _EndRecData(fp)
  File "/usr/lib/python3.9/zipfile.py", line 263, in _EndRecData
    fpin.seek(0, 2)
TypeError: seek() takes 2 positional arguments but 3 were given
valq7711 commented 3 months ago

@biffyw Hi! I will fix this asap

biffyw commented 3 months ago

Hi again,

I did an editable install of the project and fixed the function signature, but then this happened:

  File "/usr/lib/python3.9/zipfile.py", line 722, in __init__
    self.seekable = file.seekable
AttributeError: 'BytesIOProxy' object has no attribute 'seekable'

So I added the Seekable attribute and now my use case works as expected. Here is the diff:

diff --git a/ombott/request_pkg/multipart.py b/ombott/request_pkg/multipart.py
index fc5b7e6..d0b13b7 100644
--- a/ombott/request_pkg/multipart.py
+++ b/ombott/request_pkg/multipart.py
@@ -345,7 +345,7 @@ class BytesIOProxy:
     def tell(self) -> int:
         return self._pos - self._st

-    def seek(self, pos: int):
+    def seek(self, pos: int, whence: int = 0):
         if pos < 0:
             pos = 0
         self._pos = min(self._st + pos, self._end)
@@ -365,6 +365,9 @@ class BytesIOProxy:
     def writable(self) -> bool:
         return False

+    def seekable(self) -> bool:
+        return True
+
     def fileno(self):
         raise OSError('Not supported')
valq7711 commented 3 months ago

@biffyw fine! But i think we need to implement whence-feature as it should be

valq7711 commented 2 months ago

@biffyw Hi!, test, please: https://github.com/valq7711/ombott/tree/improve-bytes-io-proxy

biffyw commented 2 months ago

Working as expected, thank you! This being the first time I've opened an issue , do I close it or do you?

biffyw commented 2 months ago

FYI, I saw this in the py4web group: https://groups.google.com/g/py4web/c/7TfrgaZDVzI