Dear all,


I am writing you to share with you this error that emerged with my CDSAPI python code to retrieve ERA5 data.

I am working on Windows and I managed to correctly install and use the CDSAPI to download some data.

However, I am not really sure what changed now, but I am not able to download anymore. On a test code like the following:

 

the following error comes up:

runfile('Z:/hard_drive/python/myScripts/ERA5/trial_to_erase_windows.py', wdir='Z:/hard_drive/python/myScripts/ERA5')
2019-08-23 10:24:32,471 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels
Traceback (most recent call last):

File "<ipython-input-1-4b5119c3f1d2>", line 1, in <module>
runfile('Z:/hard_drive/python/myScripts/ERA5/trial_to_erase_windows.py', wdir='Z:/hard_drive/python/myScripts/ERA5')

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 95, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)

File "Z:/hard_drive/python/myScripts/ERA5/trial_to_erase_windows.py", line 35, in <module>
'download.nc')

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\cdsapi\api.py", line 280, in retrieve
result = self._api('%s/resources/%s' % (self.url, name), request)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\cdsapi\api.py", line 298, in _api
timeout=self.timeout)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\cdsapi\api.py", line 413, in wrapped
r = call(*args, **kwargs)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\requests\sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\requests\sessions.py", line 519, in request
prep = self.prepare_request(req)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\requests\sessions.py", line 462, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\requests\models.py", line 317, in prepare
self.prepare_auth(auth, url)

File "C:\Users\ameucci\AppData\Local\Continuum\anaconda2\lib\site-packages\requests\models.py", line 548, in prepare_auth
r = auth(self)

TypeError: 'tuple' object is not callable


Do you have any idea of what happened?

Also, few info more:

I have configured my .cdsapirc file as indicated on the website.

I installed the cdsapi with conda environment


Thank you in advance for your help,

Alberto

11 Comments

  1. Hi Alberto,

    I was able to run your script and download the data. Can you login to the CDS at

    https://cds.climate.copernicus.eu/api-how-to

    and check that your .cdsapirc file matches what is shown in the black box under "Install the CDS API key" (i.e. check there are no hidden characters, etc)

    Thanks,

    Kevin

    C3S User Support




  2. If your .cdsapirc file looks ok, you could try using the latest version of the CDS API: 

    CDS API 0.1.6 has been released

    (if you have not already upgraded).

    Thanks,

    Kevin

  3. Hi Kevin,


    I tried both cdsapi 0.1.6 and cdsapi 0.2.3 but still the same error is popping out.

    I checked the .cdsapirc file and it is corresponding to the onw on the website with my UID and API key.

    This is how I wrote it:

    url: https://cds.climate.copernicus.eu/api/v2
    key: 'UID':'API key'


    Is this a problem with conda environment? However, it is quite a confusing error since two weeks ago I was able to run the code with conda environment.

    Let me know if you have any suggestions. I ran out of ideas.

    Thank you again for your help,

    Alberto

  4. I now tried to re-install anaconda from scratch.

    Then again, I installed cdsapi and configured C:\Users\Username\.cdsapirc file. Still returning the same error.

    I also tried another UID and key from a colleague. It still returns the same confusing error.

    It might not be a problem with the .cdsapirc file.


    If you have any idea of what is going on please let me know.

    Thank you,

    Alberto

  5. Hi Alberto,

    If you logon to the CDS and go to the page https://cds.climate.copernicus.eu/api-how-to , in the black box under "Install the CDS API key" you should see the text for the .cdsapirc file with the 'UID' and 'API key' replaced by the values corresponding to your account, e.g. for a different user, this could be:

    url: https://cds.climate.copernicus.eu/api/v2
    key: 123:ba2c0e66-b266-443f-9c06-054ffc0d7cb9

    where UID = '123'

    and 'API key' = 'ba2c0e66-b266-443f-9c06-054ffc0d7cb9'

    so this user's .cdsapirc key would contain:

    url: https://cds.climate.copernicus.eu/api/v2
    key: 123:ba2c0e66-b266-443f-9c06-054ffc0d7cb9

    Hope that helps,

    Kevin

  6. Kevin,

    I checked my .cdsapirc file and it is correct. However, the error is still there. I have no idea what could be the reason.

    The ecmwfapi works, the cdsapi doesn't. The same codes I am trying to run, work on a colleague's Windows 10.

    I hope this to be of help in case you find any similar cases.


    Thank you,

    Alberto

  7. did you resolve it?

    I meet the same errors, today

    1. Hi,

      could you try to insert the url and key in the script like in the example:

      import cdsapi
      c = cdsapi.Client(url='https://cds.climate.copernicus.eu/api/v2', key='123:ba2c0e66-b266-443f-9c06-054ffc0d7cb9')
      c.retrieve(
          'reanalysis-era5-pressure-levels',
          {
              'day': '01',
              'product_type': 'reanalysis',
              'variable': 'temperature',
              'pressure_level': '1000',
              'year': '2008',
              'month': '01',
              'time': '12:00',
              'format': 'netcdf',
          },
          'download.nc')

      Thanks

      Michela

      1. Thanks, 

        but it can't work

        same error

      2. Dear Michela

        I´m sorry about contacting this way, but I could find your e-mail.

        My name is Ernesto Ortiz and I'm from Chile.

        You made a python script to read a netcdf file and save the data to a csv file. However your script consider 3 dimensions and I have only two: latitude and longitude. Could it be possible to modify the script to save lat, lon and N20 to a csv file. My e.mail is ernesto.ortiz.ananias@gmail.com. I can read the netcdf file but I do not know how to write the csv file.

        Best regards, Ernesto

  8. Hi Elena,


    unfortunately, I gave up on this, because I had other pressing tasks to do.

    I hope you will have more luck. I still haven't get back to download ERA5, but in case I do I will let you know. 

    If you manage to solve the problem I would be happy to hear what happened.


    Regards,

    Alberto