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

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

Open
biffyw opened this issue Jun 27, 2024 · 6 comments
Open

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

biffyw opened this issue Jun 27, 2024 · 6 comments

Comments

@biffyw
Copy link

biffyw commented Jun 27, 2024

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
Copy link
Owner

valq7711 commented Jul 2, 2024

@biffyw Hi! I will fix this asap

@biffyw
Copy link
Author

biffyw commented Jul 3, 2024

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
Copy link
Owner

valq7711 commented Jul 3, 2024

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

@valq7711
Copy link
Owner

valq7711 commented Jul 7, 2024

@biffyw
Copy link
Author

biffyw commented Jul 9, 2024

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

@biffyw
Copy link
Author

biffyw commented Jul 24, 2024

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

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