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

Issue with Downloading a File #90

Open
vichmartins opened this issue Sep 6, 2022 · 0 comments
Open

Issue with Downloading a File #90

vichmartins opened this issue Sep 6, 2022 · 0 comments

Comments

@vichmartins
Copy link

vichmartins commented Sep 6, 2022

I kept getting the following error after running the initial download method, below are both the example code I ran and Traceback I got back:

from mega import Mega

mega = Mega()

m = mega.login('<USERNAME>',
               '<PASSWORD>')

files = m.find('archive.zip')

m.download(files, "D:\\Documents\\")
Traceback (most recent call last):
  File "C:\Users\Gpx45\Documents\Programs\python\downloader\main.py", line 14, in <module>
    m.download(files, "D:\\Documents\\")
  File "C:\Users\Gpx45\AppData\Local\Programs\Python\Python310\lib\site-packages\mega\mega.py", line 564, in download
    return self._download_file(file_handle=None,
  File "C:\Users\Gpx45\AppData\Local\Programs\Python\Python310\lib\site-packages\mega\mega.py", line 745, in _download_file
    shutil.move(temp_output_file.name, output_path)
  File "C:\Users\Gpx45\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 836, in move
    os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Gpx45\\AppData\\Local\\Temp\\megapy_emosqh_9'

Which I though it strange being that the download stream wasn't closed before it tried to move the file into the specified directory.

After looking online for a bit I found that someone had a similar problem and they fixed it by adding temp_output_file.close() function above the shutil.move() function.

I applied the fix to line 745 and it worked like a charm.

Here is the SO link:
https://stackoverflow.com/questions/68465210/problem-downloading-mega-files-with-python/68465437#68465437

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
@vichmartins and others