From 0457ca3df880d3b45d9052ae35deec32a645adfe Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 23 May 2019 15:11:09 -0700 Subject: [PATCH 1/2] Fall back on requests module when urllib fails to load a URL This can happen on systems where OpenSSL is too old. --- tools/system_libs.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/system_libs.py b/tools/system_libs.py index 18a80a623f38..5e6049eea1b4 100755 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -926,11 +926,23 @@ def retrieve(): logger.warning('retrieving port: ' + name + ' from ' + url) try: from urllib.request import urlopen + f = urlopen(url) + data = f.read() except ImportError: # Python 2 compatibility - from urllib2 import urlopen - f = urlopen(url) - data = f.read() + from urllib2 import urlopen, URLError + try: + f = urlopen(url) + data = f.read() + except URLError as e: + try: + import requests + response = requests.get(url) + data = response.content + except: + # give up, but raise the original URLError + raise e + open(fullpath, 'wb').write(data) State.retrieved = True From 41d2da85abed1721ff628f413c0f56a97651c701 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 23 May 2019 15:51:13 -0700 Subject: [PATCH 2/2] try requests first --- tools/system_libs.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/system_libs.py b/tools/system_libs.py index 5e6049eea1b4..c13a72b28048 100755 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -925,23 +925,19 @@ def retrieve(): # retrieve from remote server logger.warning('retrieving port: ' + name + ' from ' + url) try: - from urllib.request import urlopen - f = urlopen(url) - data = f.read() + import requests + response = requests.get(url) + data = response.content except ImportError: - # Python 2 compatibility - from urllib2 import urlopen, URLError try: + from urllib.request import urlopen + f = urlopen(url) + data = f.read() + except ImportError: + # Python 2 compatibility + from urllib2 import urlopen f = urlopen(url) data = f.read() - except URLError as e: - try: - import requests - response = requests.get(url) - data = response.content - except: - # give up, but raise the original URLError - raise e open(fullpath, 'wb').write(data) State.retrieved = True