cdsapi icon indicating copy to clipboard operation
cdsapi copied to clipboard

Setting `retry_max` to `0` raises error

Open BSchilperoort opened this issue 1 year ago • 0 comments

To avoid retrying downloads (as they corrupt my request #66 ), I attempted to set retry_max=0 in the client definition. However, this causes cdsapi to fail completely.

I believe the offending line is here: https://github.com/ecmwf/cdsapi/blob/85351e4a835a16fff2d64da0f203e0c523432cc1/cdsapi/api.py#L106-L109

It seems that there is an off-by-one mistake here: I would expect that when retry_max is set to 0, that a single attempt would be made. Currently, if retry_max=n, the number of retries is n-1. The comparison should therefore be:

    while tries <= self.retry_max:

My stack trace:

2023-02-28 13:11:00,405 INFO Welcome to the CDS
2023-02-28 13:11:00,406 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/satellite-lai-fapar
Traceback (most recent call last):
  File "usr\venvs\ecoextreml\lib\site-packages\cdsapi\api.py", line 427, in _api
    result.raise_for_status()
AttributeError: 'NoneType' object has no attribute 'raise_for_status'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "usr\venvs\ecoextreml\lib\site-packages\cdsapi\api.py", line 433, in _api
    reply = result.json()
AttributeError: 'NoneType' object has no attribute 'json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "usr\download_scripts\download_FAPAR_LAI.py", line 46, in <module>
    get_data(c, year=2010)
  File "usr\download_scripts\download_FAPAR_LAI.py", line 20, in get_data
    cds_client.retrieve(
  File "usr\venvs\ecoextreml\lib\site-packages\cdsapi\api.py", line 348, in retrieve
    result = self._api("%s/resources/%s" % (self.url, name), request, "POST")
  File "usr\venvs\ecoextreml\lib\site-packages\cdsapi\api.py", line 435, in _api
    reply = dict(message=result.text)
AttributeError: 'NoneType' object has no attribute 'text'

BSchilperoort avatar Feb 28 '23 12:02 BSchilperoort