@@ -519,6 +519,23 @@ def handle_live_pirs(infile, fsize):
519519
520520# End of code taken from extract360.py.
521521
522+ def urlopen_timeout_retry (request , attempts = 5 ):
523+ import socket
524+
525+ last_error = None
526+ for attempt in range (attempts ):
527+ try :
528+ return urlopen (request )
529+ except URLError , e :
530+ if isinstance (e .reason , socket .timeout ):
531+ print ("Timeout! " , e )
532+ else : raise
533+ last_error = e
534+ except socket .timeout , e :
535+ print ("Timeout! " , e )
536+ last_error = e
537+ raise last_error
538+
522539def getFileOrURL (filename , url ):
523540 # Check if a file named filename exists on disk.
524541 # If so, return its contents. If not, download it, save it, and return its
@@ -530,16 +547,11 @@ def getFileOrURL(filename, url):
530547 return retval
531548 except IOError :
532549 pass
550+
533551 print ("Downloading" , filename , "from" , url )
534- req = Request (url , headers = {'User-Agent' : 'Mozilla/5.0' })
535- try :
536- response = urlopen (req )
537- except URLError as e :
538- if hasattr (e , 'reason' ):
539- print ("Failed to reach download server. Reason:" , e .reason )
540- elif hasattr (e , 'code' ):
541- print ("The server couldn't fulfill the request. Error code:" ,
542- e .code )
552+ request = Request (url , headers = {'User-Agent' : 'Mozilla/5.0' })
553+ response = urlopen_timeout_retry (request )
554+
543555 print ("Reading response..." )
544556 retval = response .read ()
545557 # Save downloaded file to disk
@@ -564,7 +576,7 @@ def extractPirsFromZip(systemupdate):
564576 target = sys .argv [1 ]
565577 if not os .path .isfile (target ):
566578 fw = getFileOrURL ("SystemUpdate.zip" ,
567- "http ://www.xbox.com/system-update-usb" )
579+ "https ://www.xbox.com/system-update-usb" )
568580 pirs = extractPirsFromZip (fw )
569581
570582 lang = ["English" , "Japanese" , "German" , "French" , "Spanish" ,
0 commit comments