我正试图使用Python的mega.py
库中的以下代码从我的MEGA帐户下载一个文件:
from mega import Mega
mega = Mega()
m = mega.login('example@example.com', 'example')
file = m.find('example.txt')
m.download(file, 'D:\\Desktop')
然而,它总是返回:
Traceback (most recent call last):
File "D:\Programas\aNaconda\lib\shutil.py", line 788, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The file is already being used by another process: 'C:\\Users\\vrida\\AppData\\Local\\Temp\\megapy_xdste432' -> 'example.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-26-c3f75106fafb>", line 1, in <module>
m.download(file)
File "D:\Programas\aNaconda\lib\site-packages\mega\mega.py", line 564, in download
return self._download_file(file_handle=None,
File "D:\Programas\aNaconda\lib\site-packages\mega\mega.py", line 745, in _download_file
shutil.move(temp_output_file.name, output_path)
File "D:\Programas\aNaconda\lib\shutil.py", line 803, in move
os.unlink(src)
PermissionError: [WinError 32] The file is already being used by another process: 'C:\\Users\\vrida\\AppData\\Local\\Temp\\megapy_example'
实际上,当我进入文件夹(C:\Users\vrida\AppData\Local\Temp)时,我发现了一个临时文件,与我想要下载的文件类似,但名为megapy\u example
我看到下面的网站有一个讨论来解决这个问题:
https://www.reddit.com/r/learnpython/comments/mw6is2/download_file_from_mega_using_megapy/
要求在代码中添加以下行:
try:
m.download(file, 'D:\\Desktop')
except PermissionError:
continue
在我的例子中,continue命令不起作用,因此我只需输入pass命令。代码运行,但我不知道文件是否真的保存了
谁能帮帮我吗?我真的需要下载文件并保存它们
如果它不能通过mega.py
库工作,你们就会知道如何通过Python从公共链接下载:
https://mega.co.nz/#!cSZCELDb!5O57KMVMIgrPiH5fnaefWeNPDqoDWzGbY-sZkdTUdNk
库中有一个bug,它在移动文件之前没有关闭文件。您可以通过编辑源代码来修复此错误:
D:\Programas\aNaconda\lib\site-packages\mega\mega.py
处打开文件745
行,其中第shutil.move(temp_output_file.name, output_path)
行为李>temp_output_file.close()
李>相关问题 更多 >
编程相关推荐