From ade8f38a0bdd2d994a98c86847e4dbaf60c8981f Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Mon, 15 Jun 2020 07:27:05 +0200 Subject: [PATCH] add error message if Google Drive quota is exceeded --- torchvision/datasets/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/torchvision/datasets/utils.py b/torchvision/datasets/utils.py index 6689eef649b..81774aee9e1 100644 --- a/torchvision/datasets/utils.py +++ b/torchvision/datasets/utils.py @@ -132,6 +132,10 @@ def list_files(root, suffix, prefix=False): return files +def _quota_exceeded(response: "requests.models.Response") -> bool: + return "Google Drive - Quota exceeded" in response.text + + def download_file_from_google_drive(file_id, root, filename=None, md5=None): """Download a Google Drive file from and place it in root. @@ -164,6 +168,14 @@ def download_file_from_google_drive(file_id, root, filename=None, md5=None): params = {'id': file_id, 'confirm': token} response = session.get(url, params=params, stream=True) + if _quota_exceeded(response): + msg = ( + f"The daily quota of the file {filename} is exceeded and it " + f"can't be downloaded. This is a limitation of Google Drive " + f"and can only be overcome by trying again later." + ) + raise RuntimeError(msg) + _save_response_content(response, fpath)