Skip to content

Commit

Permalink
fixed error for cdsapi 0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Aug 30, 2024
1 parent f6069de commit 9d37bcf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dfm_tools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def cds_credentials():
# set default for CDSAPI_URL envvar so it does not have to be supplied. This also ignores the URL in ~/.cdsapirc
os.environ["CDSAPI_URL"] = cds_url
# gets url/key from env vars or ~/.cdsapirc file
cds_url, cds_apikey, _ = cdsapi.api.get_url_key_verify(url=cds_url, key=None, verify=None)
# cds_url, cds_apikey, _ = cdsapi.api.get_url_key_verify(url=cds_url, key=None, verify=None)
c = cdsapi.Client(url=cds_url)
cds_url = c.url
cds_apikey = c.key
except Exception as e:
if "Missing/incomplete configuration file" in str(e):
# query apikey if not present in file or envvars
Expand All @@ -127,11 +130,11 @@ def cds_credentials():
c = cdsapi.Client()
# checks whether authentication is succesful (correct combination of url and apikey)
c.retrieve(name='dummy', request={})
except RuntimeError as e:
if "dataset dummy not found" in str(e):
except Exception as e:
if "dummy not found" in str(e): # Exception
# catching incorrect name, but authentication was successful
print('found ECMWF API-key and authorization successful')
elif "Authentication failed" in str(e):
elif "Authentication failed" in str(e): # HTTPError
cds_remove_credentials_raise(reason='Authentication failed')
else:
raise e
Expand Down

0 comments on commit 9d37bcf

Please sign in to comment.