Skip to content

Commit e757d52

Browse files
pmeierfmassa
andauthored
add error message if Google Drive quota is exceeded (#2321)
Co-authored-by: Francisco Massa <[email protected]>
1 parent 5247f7b commit e757d52

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

torchvision/datasets/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def list_files(root, suffix, prefix=False):
118118
return files
119119

120120

121+
def _quota_exceeded(response: "requests.models.Response") -> bool:
122+
return "Google Drive - Quota exceeded" in response.text
123+
124+
121125
def download_file_from_google_drive(file_id, root, filename=None, md5=None):
122126
"""Download a Google Drive file from and place it in root.
123127
@@ -150,6 +154,14 @@ def download_file_from_google_drive(file_id, root, filename=None, md5=None):
150154
params = {'id': file_id, 'confirm': token}
151155
response = session.get(url, params=params, stream=True)
152156

157+
if _quota_exceeded(response):
158+
msg = (
159+
f"The daily quota of the file {filename} is exceeded and it "
160+
f"can't be downloaded. This is a limitation of Google Drive "
161+
f"and can only be overcome by trying again later."
162+
)
163+
raise RuntimeError(msg)
164+
153165
_save_response_content(response, fpath)
154166

155167

0 commit comments

Comments
 (0)