From 31b27e52fbad9c7fcff0ccf1be30fcf630837df7 Mon Sep 17 00:00:00 2001 From: Tyler Sutterley Date: Mon, 6 Jul 2020 14:15:31 -0700 Subject: [PATCH] add try/except for gaierror to address #97 (#98) mac OS upgrades can lead to machines unable to get IP from hostname. this is a fix to revert to using 'localhost' in case of a gaierror from socket.gethostbyname --- icepyx/core/Earthdata.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/icepyx/core/Earthdata.py b/icepyx/core/Earthdata.py index f34be4063..dadc5955a 100644 --- a/icepyx/core/Earthdata.py +++ b/icepyx/core/Earthdata.py @@ -47,8 +47,12 @@ def __init__( def _start_session(self): #Request CMR token using Earthdata credentials token_api_url = 'https://cmr.earthdata.nasa.gov/legacy-services/rest/tokens' - hostname = socket.gethostname() - ip = socket.gethostbyname(hostname) + #try initially with machine hostname + #revert to using localhost if gaierror exception + try: + ip = socket.gethostbyname(socket.gethostname()) + except: + ip = socket.gethostbyname('localhost') data = {'token': {'username': self.uid, 'password': self.pswd,\ 'client_id': 'NSIDC_client_id','user_ip_address': ip}