@@ -519,6 +519,23 @@ def handle_live_pirs(infile, fsize):
519
519
520
520
# End of code taken from extract360.py.
521
521
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
+
522
539
def getFileOrURL (filename , url ):
523
540
# Check if a file named filename exists on disk.
524
541
# If so, return its contents. If not, download it, save it, and return its
@@ -530,16 +547,11 @@ def getFileOrURL(filename, url):
530
547
return retval
531
548
except IOError :
532
549
pass
550
+
533
551
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
+
543
555
print ("Reading response..." )
544
556
retval = response .read ()
545
557
# Save downloaded file to disk
@@ -564,7 +576,7 @@ def extractPirsFromZip(systemupdate):
564
576
target = sys .argv [1 ]
565
577
if not os .path .isfile (target ):
566
578
fw = getFileOrURL ("SystemUpdate.zip" ,
567
- "http ://www.xbox.com/system-update-usb" )
579
+ "https ://www.xbox.com/system-update-usb" )
568
580
pirs = extractPirsFromZip (fw )
569
581
570
582
lang = ["English" , "Japanese" , "German" , "French" , "Spanish" ,
0 commit comments