From 9d37bcffb7e5bbea3156f7812e33b42ddbadc065 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 30 Aug 2024 10:32:45 +0200 Subject: [PATCH] fixed error for cdsapi 0.7.2 --- dfm_tools/download.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dfm_tools/download.py b/dfm_tools/download.py index 201131a17..86a1e1d32 100644 --- a/dfm_tools/download.py +++ b/dfm_tools/download.py @@ -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 @@ -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