简体   繁体   中英

Python: PermissionError: [Errno 13] Permission denied with pydrive?

Here's my code for a very simple program:

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()

So far I am having no issues when it comes to taking the folder from the appdata location and copying it to my desktop. Where I am getting the error in my title is when I go to upload that folder and its contents on my desktop to Google Drive using pydrive.

Here's the output from the command window after running the program:

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'

I've tried running cmd as admin but am still getting the same permissions error. Any ideas?

  1. U need to check ur backup file is opening or not. if opening, close it.
  2. u can try it to move to another disk (D: or E:) to test first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM