101arrowz commited on
Commit
27a66f5
1 Parent(s): 34b66c0

don't waste bandwidth

Browse files
Files changed (1) hide show
  1. vox_celeb.py +12 -9
vox_celeb.py CHANGED
@@ -291,15 +291,18 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
291
  with catch_warnings():
292
  filterwarnings("ignore", category=InsecureRequestWarning)
293
  head = requests.get(url.format(key=cred_key), verify=False, timeout=5, stream=True)
294
- if head.status_code == 401:
295
- raise ValueError("failed to authenticate with VoxCeleb host")
296
- if head.status_code < 200 or head.status_code >= 300:
297
- raise ValueError("failed to fetch dataset")
298
- save_credentials()
299
- content_length = head.headers.get("Content-Length")
300
- if content_length is None:
301
- raise ValueError("expected non-empty Content-Length")
302
- content_length = int(content_length)
 
 
 
303
  tmp_path = Path(path + "." + sha256(url.encode("utf-8")).hexdigest())
304
  tmp_paths.append(tmp_path)
305
  lengths.append(content_length)
 
291
  with catch_warnings():
292
  filterwarnings("ignore", category=InsecureRequestWarning)
293
  head = requests.get(url.format(key=cred_key), verify=False, timeout=5, stream=True)
294
+ try:
295
+ if head.status_code == 401:
296
+ raise ValueError("failed to authenticate with VoxCeleb host")
297
+ if head.status_code < 200 or head.status_code >= 300:
298
+ raise ValueError("failed to fetch dataset")
299
+ save_credentials()
300
+ content_length = head.headers.get("Content-Length")
301
+ if content_length is None:
302
+ raise ValueError("expected non-empty Content-Length")
303
+ content_length = int(content_length)
304
+ finally:
305
+ head.close()
306
  tmp_path = Path(path + "." + sha256(url.encode("utf-8")).hexdigest())
307
  tmp_paths.append(tmp_path)
308
  lengths.append(content_length)