danielhrisca/asammdf

PermissionError during resample() for files with (video?) attachment

Closed this issue · 2 comments

Hi,
I'm getting a permission problem for .mf4 files with attachments.

Python version

'python=3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)]'
'os=Windows-10-10.0.19045'
'numpy=1.24.4'
'asammdf=7.4.2'

Code

MDF version

4.10

Code snippet

with MDF(filepath) as mf4_file:
    mf4 = mf4_file.resample(raster=0.01)

Traceback

Traceback (most recent call last):
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\site-packages\asammdf\blocks\v4_blocks.py", line 168, in __init__
    self.address = address = kwargs["address"]
KeyError: 'address'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<string>", line 2, in execute
  File "path_to_my_python_executable", line 88, in myfunction
    mf4 = mf4_file.resample(raster=0.01)
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\site-packages\asammdf\mdf.py", line 3144, in resample
    dg_cntr = mdf.append(
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\site-packages\asammdf\blocks\mdf_v4.py", line 3007, in append
    attachment_index = self.attach(
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\site-packages\asammdf\blocks\mdf_v4.py", line 6230, in attach
    at_block = AttachmentBlock(
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\site-packages\asammdf\blocks\v4_blocks.py", line 251, in __init__
    file_name.write_bytes(data)
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\pathlib.py", line 1245, in write_bytes
    with self.open(mode='wb') as f:
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\pathlib.py", line 1222, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "C:\Program Files (x86)\MyApplication\MyPythonEnvironment\lib\pathlib.py", line 1078, in _opener
    return self._accessor.open(self, flags, mode)
PermissionError: [Errno 13] Permission denied: 'NameOfMyVideoFileThatIsAttachedToTheMF4File.avi'

Description

We are shipping our python environment with our software, therefore the code will be located in the Program Files folder, which are not writable without admin rights. I believe this is the reason of the mentioned exception that is thrown during the mdf.resample() call.
The same mf4 file works when the code/python is in a folder where I have full write access. The mf4 file needs to have an attachment (in this case a video file). The mf4 file and the video.avi file are stored and used from the same folder, the attachment is not embedded. The folder for the data is writable by any user.

I also tried with specifying a "temporary_folder", but it didn't change anything. I'm a bit out of ideas. I also don't quite understand why the resample needs write access to the attached video file?

Any help would be appreciated. Let me know if it's not reproducible and/or some details about the whole issue are missing.
Thanks a lot.

@ASAA-Team please try the development branch code

@danielhrisca I can confirm. Your changes fix this issue. Thanks!

What is the timeline for the next release that will include this fix?