cdsapi key and 404 issues

I’m trying to update my scripts (running on a linux jupyterhub server) to the new API, and I’m running into some issues.

Firstly, when I follow the instructions to set the contents of my .cdsapirc file (Climate Data Store) I get:

AssertionError: The cdsapi key provided is not the correct format, please ensure it conforms to:
<UID>:<APIKEY>

If I change my .cdsapirc file to include my user ID as instructed, then the error disappears. However, I’m unable to download anything, and always get a 404 client error. I’ve attached an example below. Any thoughts as to what is going wrong?

dataset = "reanalysis-era5-pressure-levels"
request = {
    "product_type": ["reanalysis"],
    "variable": ["temperature"],
    "year": ["2018"],
    "month": ["10"],
    "day": ["11"],
    "time": [
        "08:00"
    ],
    "pressure_level": ["1000"],
    "data_format": "grib",
    "download_format": "unarchived"
}
 
client = cdsapi.Client()
client.retrieve(dataset, request).download()
2025-01-20 16:35:22,779 INFO Sending request to https://cds.climate.copernicus.eu/api/resources/reanalysis-era5-pressure-levels

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/cdsapi/api.py in _api(self, url, request, method)
    441         try:
--> 442             result.raise_for_status()
    443             reply = result.json()

/opt/anaconda3/envs/qgis/lib/python3.9/site-packages/requests/models.py in raise_for_status(self)
    942         if http_error_msg:
--> 943             raise HTTPError(http_error_msg, response=self)
    944 

HTTPError: 404 Client Error: Not Found for url: https://cds.climate.copernicus.eu/api/resources/reanalysis-era5-pressure-levels

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-3-1292a4c640e9> in <module>
     15 
     16 client = cdsapi.Client()
---> 17 client.retrieve(dataset, request).download()

~/.local/lib/python3.9/site-packages/cdsapi/api.py in retrieve(self, name, request, target)
    362 
    363     def retrieve(self, name, request, target=None):
--> 364         result = self._api("%s/resources/%s" % (self.url, name), request, "POST")
    365         if target is not None:
    366             result.download(target)

~/.local/lib/python3.9/site-packages/cdsapi/api.py in _api(self, url, request, method)
    462                         )
    463                     error = ". ".join(e)
--> 464                 raise Exception(error)
    465             else:
    466                 raise

Exception: Not Found

Most likely you are running an old version of the cdsapi package, update the package to a new release and try again.

pip install 'cdsapi>=0.7.2'

Your cdsapirc file should look like:

url: https://cds.climate.copernicus.eu/api
key: <PERSONAL-ACCESS-TOKEN>

NOT the old format UID:APIKEY

In fact there is no UID anymore!

Details are listed here:
https://cds.climate.copernicus.eu/how-to-api

1 Like

Hi Koen, I’ve got cdsapi 0.7.5 installed, the latest from conda forge.

Cheers
Ben

I created a fresh python environment with the same cdsapi 0.7.5 and the new procedure now works.

I am currently working on downloading ERA5 reanalysis data for executing GraphCast algorithm
I am using the steps in the following video: how to make prediction with graphcast
ERROR: CDS most recent date request failed: 404 Client Error: Not Found for url: https://cds.climate.copernicus.eu/api/v2.ui/resources/reanalysis-era5-single-levels

i have updated my cdsapi, created the text file named ‘.cdsapirc’… tried everything… in windows and linux, still getting the same error

Hi Ambika, it seems you are using an old url (containing v2), this explains the errors that you get. I tested the behaviour of cdsapi in case of old/incorrect credentials. this is documented on github (Clearer errors in case of incorrect authentication · Issue #137 · ecmwf/cdsapi · GitHub). The behaviour you are seeing seems to only happen in case of old urls. The same for Koen, I guess your fresh install also included a fresh ~/.cdsapirc file? Hope it helps some people.

1 Like