You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm unable to use a S3File object together with requests_toolbelt.MultipartEncoder (https://toolbelt.readthedocs.io/en/latest/user.html). The MultipartEncoder expects the File object to contain len property to calculate its size and fails with the following:
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 125, in __init__
self._prepare_parts()
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in _prepare_parts
self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in <listcomp>
self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 495, in from_field
return cls(headers, body)
^^^^^^^^^^^^^^^^^^
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 488, in __init__
self.len = len(self.headers) + total_len(self.body)
^^^^^^^^^^^^^^^^^^^^
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 432, in total_len
if hasattr(o, 'len'):
^^^^^^^^^^^^^^^^^
File "/home/krzysztof/venvs/py311/lib/python3.11/site-packages/requests_toolbelt/multipart/encoder.py", line 573, in len
return total_len(self.fd) - self.fd.tell()
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
Could you consider adding len property to S3File objects?
The text was updated successfully, but these errors were encountered:
kformanowicz-dotdata
changed the title
Add len property to S3File class
Mrequests_toolbelt.MultipartEncoder fails to encode S3File objects due to missing len property
Jan 21, 2025
kformanowicz-dotdata
changed the title
Mrequests_toolbelt.MultipartEncoder fails to encode S3File objects due to missing len property
requests_toolbelt.MultipartEncoder fails to encode S3File objects due to missing len property
Jan 21, 2025
One subtle problem, is that files already can be iterated, but the unit is one line rather than one character. So len(list(file)) will not be the same as then len we are talking about above.
Hello,
I'm unable to use a S3File object together with
requests_toolbelt.MultipartEncoder
(https://toolbelt.readthedocs.io/en/latest/user.html). TheMultipartEncoder
expects the File object to containlen
property to calculate its size and fails with the following:It works with a custom adapter like this:
Could you consider adding
len
property to S3File objects?The text was updated successfully, but these errors were encountered: