Auth issue using new API in python

I’m accessing the API through python using cdsapi==0.7.2 and the updated ~/.cdsapirc provided after I log in with my ECMWF credentials. However, when I try to run a script downloaded from the ERA5 website (downloading hourly surface variables), I get a string of errors linked back to authorizing my account (pasted below). Has anyone run into and solved this issue? Thanks!

TypeError Traceback (most recent call last)
/tmp/ipykernel_193875/646542888.py in
87
88 client = cdsapi.Client()
—> 89 client.retrieve(dataset, request, target).download()

~/stats_kam/lib/python3.9/site-packages/cdsapi/api.py in retrieve(self, name, request, target)
346
347 def retrieve(self, name, request, target=None):
→ 348 result = self._api(“%s/resources/%s” % (self.url, name), request, “POST”)
349 if target is not None:
350 result.download(target)

~/stats_kam/lib/python3.9/site-packages/cdsapi/api.py in _api(self, url, request, method)
415 action = session.post
416
→ 417 result = self.robust(action)(
418 url, json=request, verify=self.verify, timeout=self.timeout
419 )

~/stats_kam/lib/python3.9/site-packages/cdsapi/api.py in wrapped(*args, **kwargs)
604 while tries < self.retry_max:
605 try:
→ 606 r = call(*args, **kwargs)
607 except (
608 requests.exceptions.ConnectionError,

~/stats_kam/lib/python3.9/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
588 “”"
589
→ 590 return self.request(‘POST’, url, data=data, json=json, **kwargs)
591
592 def put(self, url, data=None, **kwargs):

~/stats_kam/lib/python3.9/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
526 hooks=hooks,
527 )
→ 528 prep = self.prepare_request(req)
529
530 proxies = proxies or {}

~/stats_kam/lib/python3.9/site-packages/requests/sessions.py in prepare_request(self, request)
454
455 p = PreparedRequest()
→ 456 p.prepare(
457 method=request.method.upper(),
458 url=request.url,

~/stats_kam/lib/python3.9/site-packages/requests/models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
318 self.prepare_cookies(cookies)
319 self.prepare_body(data, files, json)
→ 320 self.prepare_auth(auth, url)
321
322 # Note that prepare_auth must be last to enable authentication schemes

~/stats_kam/lib/python3.9/site-packages/requests/models.py in prepare_auth(self, auth, url)
554
555 # Allow auth to make its changes.
→ 556 r = auth(self)
557
558 # Update self to reflect the auth changes.

TypeError: ‘tuple’ object is not callable

You could consider adding the cdsapi key directly in the script to rule out issues with an old key on your system somewhere, see: Is there elsewhere to put the .cdsapirc file? Running it on Databricks

IF this doesn’t work, could you provide the script you use to kick the request of? Then the input could be more specific (there are some details in how you exactly formulate the request via the client that are vague).

The issue was solved by someone on the help team through creating a fresh virtual environment.

1 Like