odwyersoftware / mega.py

Python library for the https://mega.nz/ API.
https://github.com/odwyersoftware/mega.py
Apache License 2.0
349 stars 170 forks source link

[WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\megapy_xxxxx' #94

Closed VERISBABY closed 1 year ago

VERISBABY commented 1 year ago

i use mega.py to download file from mega but it shows this traceback when run the code:

from mega import Mega
mega = Mega()
m = mega.login()
## Even when i add email & password
m.download_url('https://mega.nz/file/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
----------------------------------------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
File c:\Program Files\Python310\lib\shutil.py:815, in move(src, dst, copy_function)
    814 try:
--> 815     os.rename(src, real_dst)
    816 except OSError:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\megapy_q__io935' -> 'book.png'

During handling of the above exception, another exception occurred:

PermissionError                           Traceback (most recent call last)
Cell In [8], line 4
      2 mega = Mega()
      3 m = mega.login()
----> 4 m.download_url('https://mega.nz/file/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

File c:\Program Files\Python310\lib\site-packages\mega\mega.py:639, in Mega.download_url(self, url, dest_path, dest_filename)
    637 file_id = path[0]
    638 file_key = path[1]
--> 639 return self._download_file(
    640     file_handle=file_id,
    641     file_key=file_key,
    642     dest_path=dest_path,
    643     dest_filename=dest_filename,
...
    835         copy_function(src, real_dst)
--> 836         os.unlink(src)
    837 return real_dst

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\megapy_q__io935'
catdogmat commented 1 year ago

Same

VERISBABY commented 1 year ago

i found a solution for this is add temp_output_file.close() before shutil.move(temp_output_file.name, output_path) in _download_file function in mega.py in source folder.

That means we have to close the file before moving