Python:PermissionError:[Errno 13] pydrive拒绝了权限?

问题描述

这是我的一个非常简单的程序的代码

import os,shutil
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

source_path = r"c:/users/x/appdata/roaming/medianxl/save"
destination_path = r"c:/users/x/desktop/backup_saves"

print("Contents being backed up:")
print(os.listdir(source_path))
destination = shutil.copytree(source_path,destination_path)
print("Contents successfully backed up to:",destination_path)

print("Now uploading backup saves to Google Drive...")

auth = GoogleAuth()
auth.LocalWebserverAuth()
drive = GoogleDrive(auth)

saves = drive.CreateFile()
saves.SetContentFile(r"c:/users/x/desktop/backup_saves")
saves.Upload()

到目前为止,从appdata位置取出文件夹并将其复制到我的桌面时,我还没有任何问题。我的标题出现错误的地方是当我使用pydrive将文件夹及其内容从桌面上传到Google云端硬盘时。

以下是运行程序后命令窗口中的输出

Contents being backed up:
['preferences.json','TSW','uhp_prettycolor.d2s','uhp_prettycolor.key','uhp_prettycolor.ma0','uhp_prettycolor.map']
Contents successfully backed up to: c:/users/x/desktop/backup_saves
Now uploading backup saves to Google Drive...
Your browser has been opened to visit:

    url here

Authentication successful.
Traceback (most recent call last):
  File "backup.py",line 21,in <module>
    saves.SetContentFile(r"c:/users/x/desktop/backup_saves")
  File "C:\Users\x\AppData\Local\Programs\Python\python38-32\lib\site-packages\pydrive\files.py",line 169,in SetContentFile
    self.content = open(filename,'rb')
PermissionError: [Errno 13] Permission denied: 'c:/users/x/desktop/backup_saves'

我尝试以管理员身份运行cmd,但仍然遇到相同的权限错误。有什么想法吗?

解决方法

  1. 您需要检查您的备份文件是否打开。如果打开,则将其关闭。
  2. u可以尝试将其移至另一个磁盘(D:或E :)进行测试。