Skip to content

Commit

Permalink
add try/except for gaierror to address #97 (#98)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tsutterley authored and JessicaS11 committed Sep 10, 2020
1 parent 1230f18 commit 31b27e5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions icepyx/core/Earthdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 31b27e5

Please sign in to comment.