From be9c64a9aaf24c248293849d1deb105fbd825d4e Mon Sep 17 00:00:00 2001 From: jaskaranSM Date: Tue, 24 Mar 2020 09:59:26 +0530 Subject: [PATCH] Use Service Accounts for Cloning if availble. - increase default timeout for network socket interface Signed-off-by: lzzy12 --- bot/__init__.py | 3 +++ .../mirror_utils/upload_utils/gdriveTools.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bot/__init__.py b/bot/__init__.py index 1fd6ba9..8cca93a 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -6,6 +6,9 @@ import time import aria2p import telegram.ext as tg from dotenv import load_dotenv +import socket + +socket.setdefaulttimeout(600) botStartTime = time.time() if os.path.exists('log.txt'): diff --git a/bot/helper/mirror_utils/upload_utils/gdriveTools.py b/bot/helper/mirror_utils/upload_utils/gdriveTools.py index e6f81dc..0a7879c 100644 --- a/bot/helper/mirror_utils/upload_utils/gdriveTools.py +++ b/bot/helper/mirror_utils/upload_utils/gdriveTools.py @@ -228,7 +228,20 @@ class GoogleDriveHelper: body = { 'parents': [dest_id] } - return self.__service.files().copy(supportsAllDrives=True, fileId=file_id, body=body).execute() + + try: + res = self.__service.files().copy(supportsAllDrives=True,fileId=file_id,body=body).execute() + return res + except HttpError as err: + if err.resp.get('content-type', '').startswith('application/json'): + reason = json.loads(err.content).get('error').get('errors')[0].get('reason') + if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded': + if USE_SERVICE_ACCOUNTS: + self.switchServiceAccount() + LOGGER.info(f"Got: {reason}, Trying Again.") + self.copyFile(file_id,dest_id) + else: + raise err def clone(self, link): self.transferred_size = 0