1212import logging
1313import json
1414import re
15- import urllib3 as urllib
15+ import urllib3
1616# import urllib.request
1717
1818LOG = logging .getLogger (__name__ )
2121# location of backing APOD service
2222BASE = 'https://apod.nasa.gov/apod/'
2323
24+ # Create urllib3 Pool Manager
25+ http = urllib3 .PoolManager ()
2426
2527# function for getting video thumbnails
2628def _get_thumbs (data ):
@@ -37,9 +39,9 @@ def _get_thumbs(data):
3739vimeo_id_regex = re .compile ("(?:/video/)(\d+)" )
3840vimeo_id = vimeo_id_regex .findall (data )[0 ]
3941# make an API call to get thumbnail URL
40- with urllib .request . urlopen ( " https://vimeo.com/api/v2/video/"+ vimeo_id + ".json" )as url :
41- data = json .loads (url . read () .decode ())
42- video_thumb = data [0 ]['thumbnail_large' ]
42+ vimeo_request = http .request ( "GET" , " https://vimeo.com/api/v2/video/"+ vimeo_id + ".json" )
43+ data = json .loads (vimeo_request . data .decode ('utf-8' ))
44+ video_thumb = data [0 ]['thumbnail_large' ]
4345else :
4446# the thumbs parameter is True, but the APOD for the date is not a video, output nothing
4547video_thumb = ""