diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-08-17 20:44:42 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-08-17 20:44:42 +0100 |
| commit | 9480e00023b1315609000cf256c59425e9efdccd (patch) | |
| tree | 53259b8ed39a6e9d9b39cb894a2e45780c666f42 /datasets/scanline_126007/get_scanline_126007.py | |
| parent | Add retries to the get_measles script (diff) | |
| download | TCPD-9480e00023b1315609000cf256c59425e9efdccd.tar.gz TCPD-9480e00023b1315609000cf256c59425e9efdccd.zip | |
Add retries to all download scripts
Diffstat (limited to 'datasets/scanline_126007/get_scanline_126007.py')
| -rw-r--r-- | datasets/scanline_126007/get_scanline_126007.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/datasets/scanline_126007/get_scanline_126007.py b/datasets/scanline_126007/get_scanline_126007.py index ba41774..7845bb1 100644 --- a/datasets/scanline_126007/get_scanline_126007.py +++ b/datasets/scanline_126007/get_scanline_126007.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/20070611200633im_/http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/BSDS300/html/images/plain/normal/gray/126007.jpg" @@ -70,7 +73,20 @@ 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) |
