Confusing error message for invalid key
If the API key (by accident) is set to an invalid value:
$ cat .cdsapirc
url: https://cds.climate.copernicus.eu/api/v2
key: dummy
and we run the test example:
>>> import cdsapi
>>> cds = cdsapi.Client()
>>> cds.retrieve('reanalysis-era5-pressure-levels', {
"variable": "temperature",
"pressure_level": "1000",
"product_type": "reanalysis",
"date": "2017-12-01/2017-12-31",
"time": "12:00",
"format": "grib"
}, 'download.grib')
we get an error message which is not very informative:
2019-05-15 08:54:26,421 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-pressure-levels
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "/home/jbl/.local/lib/python3.6/site-packages/cdsapi/api.py", line 230, in retrieve
result = self._api('%s/resources/%s' % (self.url, name), request)
File "/home/jbl/.local/lib/python3.6/site-packages/cdsapi/api.py", line 245, in _api
result = self.robust(session.post)(url, json=request, verify=self.verify)
File "/home/jbl/.local/lib/python3.6/site-packages/cdsapi/api.py", line 362, in wrapped
r = call(*args, **kwargs)
File "/home/jbl/.local/lib/python3.6/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/home/jbl/.local/lib/python3.6/site-packages/requests/sessions.py", line 519, in request
prep = self.prepare_request(req)
File "/home/jbl/.local/lib/python3.6/site-packages/requests/sessions.py", line 462, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/home/jbl/.local/lib/python3.6/site-packages/requests/models.py", line 317, in prepare
self.prepare_auth(auth, url)
File "/home/jbl/.local/lib/python3.6/site-packages/requests/models.py", line 548, in prepare_auth
r = auth(self)
TypeError: 'tuple' object is not callable
Hi. jblarsen
It might be caused by abnormal 'key' information. The 'key' must set as follows; 'uid: key'
Best, YC
Hi jblarsen,
I have exactly the same error running the same test example and my code as well.
I tried to modify the .cdsapirc file with 'uid: key' but I still couldn't solve the problem. Have you solve this problem? Do you have any idea of what is the issue?
Thank you.
Regards, al
Sorry, I don't know. It works for me when I specify "uid:key" (no spaces).
Thank you jblarsen,
I tried as you suggested but it still doesn't work for me. It keeps on giving me the same error.
TypeError: 'tuple' object is not callable
This how I wrote the .cdsapirc as indicated in Copernicus Data Storage web page [https://cds.climate.copernicus.eu/api-how-to]
url: https://cds.climate.copernicus.eu/api/v2 key: <UID>:<API key>
I tried both cdsapi 0.1.6 and the newer cdsapi 0.2.3 versions. Both are not working.
Have you ever heard any similar error? Do you know what might cause this? I am working in a conda environment.
Thank you very much again for your help, Al
ERRATA CORRIGE:
url: https://cds.climate.copernicus.eu/api/v2 key: ''UID'':''API key''
Sorry, I haven't encountered that.
Hi Guys,
Can I ask if you are installing the "cdsapi" from Windows or not. Unfortunately in spite of installing the , but I still have the following error:
"ModuleNotFoundError: No module named 'cdsapi' which is for sure related to the cdsapi installation.
I used command prommpt and pip to install cdsapi: pip install cdsapi
and all is running without error.
Any help is really appreciated.
Thanks,
Saeed
I am using Linux but one reason could be that pip installs it for another Python version than the one you are using. For example if you have both Python 2 and 3 installed. You can run pip -V to check which Python version it is from.
I have had the same issue.
In your .cdsapirc file you will have to add the following:
url: https://cds.climate.copernicus.eu/api/v2
key: [UID]:[API Key]
In order to access ones UID and ones API Key one can follow this link: https://cds.climate.copernicus.eu/user (one needs to be logged in).
Hi, Guys, I set the UID:API as above recommend, but there is still having an error: can anyone know where is wrong? I used Anaconda3 in Windows. Thank you
(D:\Anaconda3) C:\Users\HP>cat .cdsapirc url: https://cds.climate.copernicus.eu/api/v2 key: 53**********6ba
(D:\Anaconda3) C:\Users\HP>python Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import cdsapi cds = cdsapi.Client() cds.retrieve('reanalysis-era5-pressure-levels', { ... "variable": "temperature", ... "pressure_level": "1000", ... "product_type": "reanalysis", ... "date": "2017-12-01/2017-12-31", ... "time": "12:00", ... "format": "grib" ... }, 'download.grib') 2020-08-03 20:50:04,968 INFO Welcome to the CDS 2020-08-03 20:50:04,970 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-pressure-levels 2020-08-03 20:50:07,357 INFO Request is completed 2020-08-03 20:50:07,358 INFO Downloading http://136.156.133.36/cache-compute-0010/cache/data6/adaptor.mars.internal-1596450246.9105744-27982-17-42a38ba0-d714-4286-b3a3-759ae8a83e74.grib to download.grib (61.4M) Traceback (most recent call last): File "
", line 8, in File "D:\Anaconda3\lib\site-packages\cdsapi\api.py", line 331, in retrieve result.download(target) File "D:\Anaconda3\lib\site-packages\cdsapi\api.py", line 167, in download target) File "D:\Anaconda3\lib\site-packages\cdsapi\api.py", line 125, in _download leave=False, TypeError: 'module' object is not callable
I had same problem. After login to Copernicus website and accepting the license terms at following URL, my problem solved:
https://cds.climate.copernicus.eu/cdsapp/#!/terms/licence-to-use-copernicus-products
I think the error message comes because when you don't provide <UID>:<API_KEY> but e.g. only <API_KEY>, you will end up with a tuple with only one element after the split(":") in https://github.com/ecmwf/cdsapi/blob/24f0a4e/cdsapi/api.py#L324
You can pass either a tuple with ("username", "password") to requests, or a callable. So requests sees this isn't a tuple with len 2, and tries to call it. Hence the error message.
I think it would be good to check whether the result of the split actually has 2 elements, and raise a more descriptive error when not.
This issue will be resolved with the next release of the cdsapi