0

Workround: Since I only need access to spreadsheets , I used gspread instead , oauth2 is much simpler with it

Im trying to download a file using pydrive (python google drive api)

My code worked for me ,I didn't change anything but now it wont work

I made sure to make the file public (even though it worked even when it was private)

This is the relevant part of the code:

gauth = GoogleAuth()
gauth.GetFlow()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
    # Authenticate if they're not there
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    # Refresh them if expired
    gauth.flow.params.update({'access_type': 'offline'})
    gauth.Refresh()
else:
    # Initialize the saved creds
    gauth.Authorize()


drive = GoogleDrive(gauth)
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")

file1 = drive.CreateFile({'id': '1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws'})
file1.GetContentFile('Hello.csv', mimetype='text/csv')

This is the error I get in the console :

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

And this is what the link above shows:

{
 "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."
 }
}

Any help appreciated , thanks

Edit : these is what I see inside the credentials of my gauth object , anything missing? Credentials

Ron Serruya
  • 3,988
  • 1
  • 16
  • 26
  • 1
    The error means your authentication isn't working its probably not being applied correctly try this https://stackoverflow.com/questions/24419188/automating-pydrive-verification-process – Linda Lawton - DaImTo May 29 '17 at 09:18
  • @DaImTo This is actually the link I used to create the automatic process for authentication , the thing is that it worked perfectly one day , and got broken the other day without any change – Ron Serruya May 29 '17 at 09:41
  • 1
    check the order you have gauth.SaveCredentialsFile vs drive = GoogleDrive(gauth) in. try and remove the file and reauthenticate the code. – Linda Lawton - DaImTo May 29 '17 at 09:54
  • @DaImTo Tried it a few times , I always authenticate successfully (Web page open , I select my account and allow access to drive) , still no change Anything I should check to see if im missing inside the gauth object? – Ron Serruya May 29 '17 at 13:08
  • Your question has two different errors, a 404 and a 403 - please explain which lines in your code create these errors. You have a 3-way if - please add some debugging and let us know which execution path was taken. Check the value of Access Token in the gauth object. Try going into Google accounts and removing the authorization for your app, – pinoyyid May 29 '17 at 22:33
  • 1
    @pinoyyid 404 error means that the current loged in user does not have access to the file 1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws 403 error means that he is not logged in which causes the first 404 error assuming that the file is not set to public. These errors can go side by side. – Linda Lawton - DaImTo May 30 '17 at 06:43
  • im facing same issue as @RonSerruya. I accept 403 because we just access directly the url given in the error message. what i dont get is why 404, even the file exist. – ji-ruh Feb 01 '21 at 12:36

1 Answers1

0

I think you can try hitting the files.get api from postman using an active access token from your credentials file.

If it gives 401, that means your access token is not correct.

If it gives 404, it means you don't have access to the file or the file is deleted.

Kunal Chawla
  • 119
  • 1
  • 8