Dear sakvaka_env
Here is fixed ancillary.py file. Could you find any errors? thanks the error : line 375 try: IndentationError: expected an indented block .
Best, Binbin
assert basename(url) == basename(target)
class NonFatalException(Exception):
def __init__(self, message="A non-fatal exception occurred"):
self.message = message
super().__init__(self.message)
with LockFile(lock):
# follows
https://support.earthdata.nasa.gov/inde ... l-and-wget
cmd = 'wget -nv --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies --auth-no-challenge {} -O {}'.format(url, target+'.tmp')
ret = system(cmd)
if ret == 0:
try:
if ret != 0:
raise Exception(f'Wget returned a non-zero error code: {ret}')
# sanity check
# raise an error in case of authentication error
# check that downloaded file is not HTML
with open(target+'.tmp', 'rb') as fp:
filehead = fp.read(100)
errormsg = 'Error authenticating to NASA EarthData for downloading ancillary data. ' \
'Please provide authentication through .netrc. See more information on ' \
'
https://support.earthdata.nasa.gov/inde ... l-and-wget'
assert not fp.read(100).startswith(b'<!DOCTYPE html>'), errormsg
assert not filehead.startswith(b'<!DOCTYPE html>'), errormsg
# may be the case after Oct 2023 when NASA changed the APIs
if filehead.startswith(b'404 Error'):
raise NonFatalException(filehead.decode('utf-8'))
cmd = 'mv {} {}'.format(target+'.tmp', target)
system(cmd)
else:
except NonFatalException as e:
print(f"A non-fatal exception occurred: {e}")
ret = 1
finally:
if exists(target+'.tmp'):
system('rm {}'.format(target+'.tmp'))
return ret
def try_resource(self, pattern, date):
"""
Try to access pattern (string, like 'N%Y%j%H_MET_NCEP_1440x0721_f015.hdf')
at a given date
"""
target = date.strftime(join(self.directory, '%Y/%j/'+pattern))
if exists(target):
return target
url = date.strftime(self.url+pattern)
if not self.offline:
print('Trying to download', url, '... ')
sys.stdout.flush()
ret = self.download(url, target)
if ret == 0:
target = verify(target)
return target
else:
print('failure ({})'.format(ret))
return None
def find(self, date, patterns):
'''
Try to access offline or online resource defined by patterns,
at `date`
'''
for pattern in patterns:
res = [self.try_resource(pat, d) for pat, d in pattern(date)]
if None not in res:
return res