3

I am using python to fetch files from the google shared drive, which is owned by the team. The currently issue is I can parse all the file ID's but I cannot using the pyDrive to download or read the content of the file.

First I generated a "drive":

from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
from pprint import pprint

gauth = GoogleAuth()
# Create local webserver and auto handles authentication.
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

Then I use the file id to get the content:

file_id = 'xxx'
file_ = drive.CreateFile({'id': file_id})
content = file_.GetContentString() # <--------------problem line
print(content)

The error I got is:

pydrive.files.ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/xxx?alt=json returned "File not found: xxx">

However, the file does exist when I go to the https://www.googleapis.com/drive/v2/files/xxx?alt=json, it return:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Bill Chen
  • 1,699
  • 14
  • 24

1 Answers1

2

what file id ,you check the pydrive documentation to download it will be weird because you have to upload a file to actually download it

You also seem to use GetContentString it can only get strings you can use GetContentFile to get all types of files

The Below code will download the file you need try it

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

#1st authentification
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles
#authentication.
drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': 'Hello.txt'})
file1.Upload()

file6 = drive.CreateFile({'id' : file1['id']})
file6.GetContentFile('enter the file name you want to download here')

file1.Delete()
loginer
  • 21
  • 2