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

2024-09-26 22:53:28 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我编写的一个非常简单的程序代码:

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 Drive时,标题中出现了错误

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

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,但仍然得到相同的权限错误。有什么想法吗


Tags: topathauthcontentsdestinationusersbackupprint

热门问题