winfreed.py: check if Content-Length is available before downloading
authorAntonio Ospite <ao2@ao2.it>
Sun, 30 Aug 2015 10:31:23 +0000 (12:31 +0200)
committerAntonio Ospite <ao2@ao2.it>
Sun, 30 Aug 2015 10:31:23 +0000 (12:31 +0200)
winfreed.py

index 0492028..a9af707 100755 (executable)
@@ -108,6 +108,10 @@ def download_file(src_url, dest_dir):
         sys.stderr.write("Warning: %s exists!\n" % destfile)
         return
 
         sys.stderr.write("Warning: %s exists!\n" % destfile)
         return
 
+    if 'Content-Length' not in response.info():
+        sys.stderr.write("Cannot get the size of the file at %s\n" % src_url)
+        return
+
     total_size = response.info().getheader('Content-Length').strip()
     total_size = int(total_size)
 
     total_size = response.info().getheader('Content-Length').strip()
     total_size = int(total_size)