Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

upgrade to urlib3 for fetching GCs and colormaps

Mike McGann524ae72f9a9d
diff --git a/requirements.txt b/requirements.txt
index 715841871..d3894f071 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,3 +3,4 @@ isodate==0.6.0
six==1.11.0
wsgiref==0.1.2
xmltodict==0.11.0
+urllib3[secure]==1.23
diff --git a/tasks/getCapabilities.py b/tasks/getCapabilities.py
index 2c864c032..f616b5637 100755
--- a/tasks/getCapabilities.py
+++ b/tasks/getCapabilities.py
@@ -6,9 +6,11 @@ from collections import OrderedDict
import os
import sys
import json
-import urllib2 as urllib
+import urllib3
+import urllib3.contrib.pyopenssl
import xmltodict
import traceback
+import certifi
prog = os.path.basename(__file__)
base_dir = os.path.join(os.path.dirname(__file__), "..")
@@ -33,6 +35,12 @@ remote_count = 0
error_count = 0
warning_count = 0
+urllib3.contrib.pyopenssl.inject_into_urllib3()
+http = urllib3.PoolManager(
+ cert_reqs='CERT_REQUIRED',
+ ca_certs=certifi.where()
+)
+
if not os.path.exists(output_dir):
os.makedirs(output_dir)
@@ -60,8 +68,8 @@ def process_layer(layer):
def process_remote(entry):
url = entry["from"]
print "%s: %s" % (prog, url)
- response = urllib.urlopen(url)
- contents = response.read()
+ response = http.request('GET', url)
+ contents = response.data
output_file = os.path.join(output_dir, entry["to"])
# Write GetCapabilities responses to XML files
@@ -93,8 +101,8 @@ def process_colormaps():
os.makedirs(colormaps_dir)
for link in colormaps.values():
try:
- response = urllib.urlopen(link)
- contents = response.read()
+ response = http.request("GET", link)
+ contents = response.data
output_file = os.path.join(colormaps_dir, os.path.basename(link))
with open(output_file, "w") as fp:
fp.write(contents)
@@ -103,7 +111,6 @@ def process_colormaps():
(prog, link, str(e)))
global warning_count
warning_count += 1
- print "%s: Fetching %d colormaps" % (prog, len(colormaps))
tolerant = config.get("tolerant", False)
if "wv-options-fetch" in config: