0

I created a web app in python to copy files between my Google Drive accounts. Public shared files to my account.

I got the following error

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

I tried everything, change scopes, enable SDK in Google Console, etc. The problem is that this error seems to appear only when I am copying some files, and the app works properly for other files, even files in the same account.

I am using pydrive to handle the authentication, following how I am doing it:

def LogIn(self):
    extDataDir = os.getcwd()
    ext_config = os.path.join(extDataDir, 'client_secrets.json')
    dir_path = extDataDir
    temp_folder = extDataDir

    gauth = GoogleAuth(os.path.join(extDataDir,'settings.yaml'))
    gauth.DEFAULT_SETTINGS['client_config_file'] = ext_config
    gauth.settings['save_credentials_file'] = os.path.join(temp_folder, "cred_copyfiles.txt")
    gauth.LoadCredentialsFile(os.path.join(temp_folder, "cred_copyfiles.txt"))
    if gauth.credentials is None:
        # Authenticate if they're not there
        gauth.LocalWebserverAuth()
    elif gauth.access_token_expired:
        # Refresh them if expired
        try:
            gauth.Refresh()
        except:
            gauth.LocalWebserverAuth()
    else:
        gauth.Authorize()
    return GoogleDrive(gauth)

This is my settings.yaml

client_config_backend: settings
client_config:
  client_id: my_clent_di
  client_secret: my_client_secret

save_credentials: True
save_credentials_backend: file
save_credentials_file: cred_copyfiles.txt

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive

I copy the files using as example in Google's drive API documentation

drive.auth.service.files().copy(fileId=f['id'],body={"parents": [{"kind": "drive#fileLink","id": save_folder_id}]}).execute()

Again, It seems it is not a problem with authentication, since it works for some files and not for others. Even files in the same account. Does anyone know a solution for this problem?

EDIT: Following the suggestion, I build the authentication using the DriveAPI, by passing the pydrive, and I got the same error.

I found out how to get the request:

drive.auth.service.files().copy(fileId=f['id'],body={"parents": [{"kind": "drive#fileLink","id": save_folder_id}]}).to_json()

Here the request

{"resumable_uri": null, "resumable": null, "uri": "https://www.googleapis.com/drive/v2/files/file_id/copy?alt=json", "body_size": 79, "response_callbacks": [], "body": "{\"parents\": [{\"id\": \"file_id\", \"kind\": \"drive#fileLink\"}]}", "resumable_progress": 0, "_in_error_state": false, "method": "POST", "methodId": "drive.files.copy", "headers": {"user-agent": "google-api-python-client/1.6.1 (gzip)", "content-type": "application/json", "accept-encoding": "gzip, deflate", "accept": "application/json"}}
Rafael
  • 433
  • 6
  • 12

1 Answers1

0

The most likely explanation for that error message is that you are making a Drive request without an Authorization http header. I suggest try to capture the http request/response that is failing and paste that into your question.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • sorry, but how do I capture that? – Rafael Mar 16 '17 at 17:29
  • if you are using a library, ask the author how to turn on a debug mode to log requests. If there isn't such a mode, complain or find a better library. Alternatively, the Drive REST API is a pretty simple and standard API, so bypass the library and code your own REST calls. Don't lose sight of the fact that the error says "Unauthenticated Use Exceeded.", so it's clearly an authentication problem in your code somewhere. – pinoyyid Mar 16 '17 at 17:47
  • Just did that, I use the Drive API from zero. I got the same error. I am posting the code to my question. – Rafael Mar 16 '17 at 19:16
  • one thing, It is not all the time this error occurs. Sometimes I can copy a file, then if I try the other day I cannot (the same file). – Rafael Mar 16 '17 at 19:27
  • I hear you. Unless you can capture the request/response from a failed API call, it would be pure guesswork. – pinoyyid Mar 16 '17 at 21:47
  • Since these are "public shared files" that you're copying, can you provide a(t least one) file ID so we can try to copy those files ourselves to try to reproduce your error? – wescpy Mar 16 '17 at 23:25