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
Traceback (most recent call last):
print(resource.read_rows())
^^^^^^^^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/resources/table.py", line 423, in read_rows
with helpers.ensure_open(self):
File "python3.12/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/helpers/general.py", line 97, in ensure_open
thing.open()
File "python3.12/site-packages/frictionless/resources/table.py", line 161, in open
self.__open_parser()
File "python3.12/site-packages/frictionless/resources/table.py", line 178, in __open_parser
self.__parser.open()
File "python3.12/site-packages/frictionless/system/parser.py", line 95, in open
self.__loader = self.read_loader()
^^^^^^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/system/parser.py", line 126, in read_loader
return loader.open()
^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/system/loader.py", line 107, in open
self.__byte_stream = self.read_byte_stream()
^^^^^^^^^^^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/system/loader.py", line 137, in read_byte_stream
byte_stream = self.read_byte_stream_create()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python3.12/site-packages/frictionless/schemes/stream/loader.py", line 17, in read_byte_stream_create
if not os.path.isfile(byte_stream.name): # type: ignore
^^^^^^^^^^^^^^^^
AttributeError: '_io.BytesIO' object has no attribute 'name'
File "python3.12/site-packages/frictionless/schemes/stream/loader.py", line 17, in read_byte_stream_create
if not os.path.isfile(byte_stream.name): # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen genericpath>", line 30, in isfile
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
Is there reason frictionless expects the file object to have .name that is an actual file
in read_byte_stream_create?
Being able to pass a SpooledTemporaryFile would be particularly useful,
because FastAPI presents uploaded files as SpooledTemporaryFile instances.
The text was updated successfully, but these errors were encountered:
after frictionless does its work, we get a ValueError: seek of closed file error.
This is not ideal since we want to use frictionless to process the file, then read it again to save it somewhere else.
Thanks for the report and for the workaround. I agree that automatically closing the file may not be the best behaviour.
The part that crashes is part of an exception handling :
if not os.path.isfile(byte_stream.name): # type: ignore
note = f"only local streams are supported: {byte_stream}"
raise FrictionlessException(errors.SchemeError(note=note))
So supporting file-like in-memory data seems like a new feature to me.
However, in the meanwhile, I can at least :
make sure that the right exception with explicit error message is raised
frictionless version: 5.17.0
python version: 3.12
platform: linux
The docs here https://framework.frictionlessdata.io/docs/schemes/stream.html say data can be loaded from file-like objects,
this does work for the example given when the object is an opened file:
However for classes like
BytesIO
andSpooledTemporaryFile
it doesn't worke.g. Bytes IO
Error:
e.g. SpooledTemporaryFile
Error mostly the same except for:
Is there reason frictionless expects the file object to have
.name
that is an actual filein
read_byte_stream_create
?Being able to pass a
SpooledTemporaryFile
would be particularly useful,because FastAPI presents uploaded files as
SpooledTemporaryFile
instances.The text was updated successfully, but these errors were encountered: