question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing error message for invalid key

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jeverlingcommented, Jun 7, 2021

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.

0reactions
gmt3141commented, Feb 10, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Messages: Examples, Best Practices & Common Mistakes
4 common mistakes with error messages · 1. Ambiguity · 2. Condescending language/blaming the user · 3. Poor placement of error messages ·...
Read more >
Confusing error message when asking for invalid DSA ...
Description of problem: When system is working in FIPS mode, only specific key sizes are allowed, asking openssl for generation of other key...
Read more >
reCaptcha: error code "invalid-keys" - Stack Overflow
I can confirm, the error-code invalid-keys only returns when an existing, but incorrect account or project secret key is used.
Read more >
error "Messages got an error: Invalid key form." number -10002
Hi! Getting the following error - any insight would be much appreciated Applescript ||| error "Messages got an error: Invalid key form.
Read more >
Office 2021 for Mac - Microsoft Support
Get help with product key errors on Office.com/setup. Office 2021 Office 2021 ... This product key isn't valid (INVALID_PRODUCT_KEY or ERR_INVALID_TOKEN).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found