From 9480e00023b1315609000cf256c59425e9efdccd Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 17 Aug 2020 20:44:42 +0100 Subject: Add retries to all download scripts --- datasets/occupancy/get_occupancy.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'datasets/occupancy/get_occupancy.py') diff --git a/datasets/occupancy/get_occupancy.py b/datasets/occupancy/get_occupancy.py index 0b590fa..aa12514 100644 --- a/datasets/occupancy/get_occupancy.py +++ b/datasets/occupancy/get_occupancy.py @@ -17,9 +17,12 @@ import clevercsv import hashlib import json import os +import sys +import time from functools import wraps from urllib.request import urlretrieve +from urllib.error import URLError SAMPLE = 16 @@ -72,7 +75,19 @@ def validate(checksum): @validate(MD5_TXT) def download_txt(target_path=None): - urlretrieve(TXT_URL, target_path) + count = 0 + while count < 5: + count += 1 + try: + urlretrieve(TXT_URL, target_path) + return + except URLError as err: + print( + "Error occurred (%r) when trying to download txt. Retrying in 5 seconds" + % err, + sys.stderr, + ) + time.sleep(5) @validate(MD5_JSON) -- cgit v1.2.3