[Checkins] SVN: z3c.pypimirror/trunk/src/z3c/pypimirror/mirror.py better error handling

Andreas Jung andreas at andreas-jung.com
Wed Sep 3 03:56:12 EDT 2008


Log message for revision 90729:
  better error handling
  

Changed:
  U   z3c.pypimirror/trunk/src/z3c/pypimirror/mirror.py

-=-
Modified: z3c.pypimirror/trunk/src/z3c/pypimirror/mirror.py
===================================================================
--- z3c.pypimirror/trunk/src/z3c/pypimirror/mirror.py	2008-09-03 07:38:34 UTC (rev 90728)
+++ z3c.pypimirror/trunk/src/z3c/pypimirror/mirror.py	2008-09-03 07:56:11 UTC (rev 90729)
@@ -287,17 +287,18 @@
         # First try to determine the content-length through
         # HEAD request in order to save bandwidth
 
-        parts = urlparse.urlsplit(link)
-        c = httplib.HTTPConnection(parts[1])
-        c.request('HEAD', parts[2])
-        response = c.getresponse()
-        ct = response.getheader('content-length')
-        if ct is not None:
-            ct = long(ct)
-            return ct
+        try:
+            parts = urlparse.urlsplit(link)
+            c = httplib.HTTPConnection(parts[1])
+            c.request('HEAD', parts[2])
+            response = c.getresponse()
+            ct = response.getheader('content-length')
+            if ct is not None:
+                ct = long(ct)
+                return ct
+        except Exception, e:
+            LOG.warn('Could not obtain content-length through a HEAD request from %s (%s)' % (link, e))
 
-        LOG.warn('Could not obtain content-length through a HEAD request from %s' % link)
-
         try:
             return long(urllib2.urlopen(link).headers.get("content-length"))
         except:



More information about the Checkins mailing list