Key error cdsapi/



I tried to download glacier data. I did the following:

import cdsapi

c = cdsapi.Client()


I got the following error: 

  File "", line 40, in <module>


  File ".../lib/python2.7/site-packages/cdsapi/", line 317, in retrieve

    result = self._api('%s/resources/%s' % (self.url, name), request, 'POST')

  File ".../lib/python2.7/site-packages/cdsapi/", line 420, in _api

    if reply['state'] != self.last_state:

KeyError: u'state'

My version of cdsapi = 0.2.7 . 

Does anyone understands this specific error? 

thank you in advance! 

hi Juliette,

I just tried your script and it ran without an error and downloaded the file.

Has the CDS API worked for you before? Can you try reinstalling the CDS API on your system?



I've just encountered this error when another user tried to use one of my download scripts.

Turns out the issue was that the URL in their .cdsapirc file used `http` instead of `https` - which causes this interaction:


2021-02-23 14:07:48,975 DEBUG Starting new HTTP connection (1):
2021-02-23 14:07:49,019 DEBUG "POST /api/v2/resources/reanalysis-era5-pressure-levels HTTP/1.1" 301 169
2021-02-23 14:07:49,023 DEBUG Starting new HTTPS connection (1):
2021-02-23 14:07:49,151 DEBUG "GET /api/v2/resources/reanalysis-era5-pressure-levels HTTP/1.1" 200 None
2021-02-23 14:07:49,152 DEBUG REPLY {'slug': 'era5-hourly-data-on-pressure-levels-from-1979-to-present', 'name': 'reanalysis-era5-pressure-levels', 'id': 'eu.copernicus.climate.reanalysis-era5-pressure-levels', 'type': 'dataset', 'rich_abstract': '<div class=\'abstract-text\'>\n <p><strong>ERA5</strong> is the fifth generation ECMWF reanalysis for the global climate and weather for the past 4 to 7 decades.\nCurrently data is ava...


The error message the python script throws up isn't very helpful at the moment. Perhaps it could check for the existence of the `state` field before using it, and if it doesn't exist then return a message which suggests that the user might want to check their URL settings?