Skip to content

Commit 31b27e5

Browse files
tsutterleyJessicaS11
authored andcommittedSep 10, 2020
add try/except for gaierror to address icesat2py#97 (icesat2py#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
1 parent 1230f18 commit 31b27e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎icepyx/core/Earthdata.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ def __init__(
4747
def _start_session(self):
4848
#Request CMR token using Earthdata credentials
4949
token_api_url = 'https://cmr.earthdata.nasa.gov/legacy-services/rest/tokens'
50-
hostname = socket.gethostname()
51-
ip = socket.gethostbyname(hostname)
50+
#try initially with machine hostname
51+
#revert to using localhost if gaierror exception
52+
try:
53+
ip = socket.gethostbyname(socket.gethostname())
54+
except:
55+
ip = socket.gethostbyname('localhost')
5256

5357
data = {'token': {'username': self.uid, 'password': self.pswd,\
5458
'client_id': 'NSIDC_client_id','user_ip_address': ip}

0 commit comments

Comments
 (0)
Please sign in to comment.