Skip to content

Commit

Permalink
971 unable to download era5 data using dfmtdownload era5 (#972)
Browse files Browse the repository at this point in the history
* fixed error for cdsapi 0.7.2

* updated minimal requirement for cdsapi

* updated whatsnew
  • Loading branch information
veenstrajelmer authored Aug 30, 2024
1 parent f6069de commit 7beefb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 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
2 changes: 2 additions & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fix
- properly assigning units attribute in `ds_apply_conversion_dict()` (it did not always stick) in [#965](https://github.com/Deltares/dfm_tools/pull/965)
- skipping initialwaterlevel in `dfmt.cmems_nc_to_ini()` [#970](https://github.com/Deltares/dfm_tools/pull/970)
- update to cdsapi 0.7.2 and properly catching error for dummy dataset in [#972](https://github.com/Deltares/dfm_tools/pull/972)


## 0.25.0 (2024-08-16)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ dependencies = [
"bottleneck>=1.3.3",
#xugrid<0.11.2 sometimes fails on merged chunks that are inconsistent
"xugrid>=0.11.2",
#cdsapi<0.7.0 supports credentials from environment variables
"cdsapi>=0.7.0",
#cdsapi<0.7.2 has different error upon dummy dataset
"cdsapi>=0.7.2",
#pydap<3.4.0 is from May 2017 and does not support newer python versions
"pydap>=3.4.0",
#erddapy<2.0.0 does not support pandas>=2.0.0
Expand Down

0 comments on commit 7beefb6

Please sign in to comment.