From 6a3e7dce108b303f2248dd9c35c7d056beef23d1 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 23 May 2019 17:12:03 -0700 Subject: [PATCH] Fall back on requests module when urllib fails to load a URL (#8667) This can happen on systems where OpenSSL is too old. --- tools/system_libs.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/system_libs.py b/tools/system_libs.py index 18a80a623f38..c13a72b28048 100755 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -925,12 +925,20 @@ def retrieve(): # retrieve from remote server logger.warning('retrieving port: ' + name + ' from ' + url) try: - from urllib.request import urlopen + import requests + response = requests.get(url) + data = response.content except ImportError: - # Python 2 compatibility - from urllib2 import urlopen - f = urlopen(url) - data = f.read() + 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() + open(fullpath, 'wb').write(data) State.retrieved = True