commit 9bd473b1473e43464125431c544305e5a132c941
parent 45ee23d47b52dd55d36b3ac7bb1f5fa6ad0f5ed7
Author: parazyd <parazyd@dyne.org>
Date:   Sat, 22 Jul 2017 11:10:34 +0200
handle ReadTimeout exception in download()
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/net.py b/lib/net.py
@@ -21,15 +21,16 @@ def download(uris):
 
     try:
         r = requests.get(url, stream=True, timeout=20)
-    except requests.exceptions.ConnectionError:
-        warn("Caught exception: Connection reset. Retrying.")
+    except (requests.exceptions.ConnectionError,
+            requests.exceptions.ReadTimeout) as e:
+        warn('Caught exception: "%s". Retrying...' % e)
         return download(uris)
 
     if r.status_code == 404:
-        warn("failed: 404 not found!")
+        warn('failed: 404 not found!')
         return
     elif r.status_code != 200:
-        die("failed: %d" % r.status_code)
+        die('failed: %d' % r.status_code)
 
     makedirs(dirname(path), exist_ok=True)
     f = open(path, 'wb')