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/scanline_42049/get_scanline_42049.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'datasets/scanline_42049/get_scanline_42049.py') diff --git a/datasets/scanline_42049/get_scanline_42049.py b/datasets/scanline_42049/get_scanline_42049.py index 45f81ce..4c6e56b 100644 --- a/datasets/scanline_42049/get_scanline_42049.py +++ b/datasets/scanline_42049/get_scanline_42049.py @@ -17,10 +17,13 @@ import hashlib import os import numpy as np import json +import sys +import time from PIL import Image from functools import wraps from urllib.request import urlretrieve +from urllib.error import URLError IMG_URL = "https://web.archive.org/web/20070611230044im_/http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/BSDS300/html/images/plain/normal/gray/42049.jpg" @@ -70,7 +73,19 @@ def validate(checksum): @validate(MD5_IMG) def download_img(target_path=None): - urlretrieve(IMG_URL, target_path) + count = 0 + while count < 5: + count += 1 + try: + urlretrieve(IMG_URL, target_path) + return + except URLError as err: + print( + "Error occurred (%r) when trying to download img. Retrying in 5 seconds" + % err, + sys.stderr, + ) + time.sleep(5) @validate(MD5_JSON) -- cgit v1.2.3