ecmwf / ecmwf-api-client

Python API to access ECMWF archive
Apache License 2.0
68 stars 20 forks source link

Improve error message when invalid parameter is used #21

Open sandorkertesz opened 5 months ago

sandorkertesz commented 5 months ago

What happened?

When I use this retrieval:

import ecmwfapi

req = {
    "accumulation_period": 3,
    "grid": "O96",
    "levtype": "sfc",
    "param": ["cp", "sf", "tp"],
    "type": "fc",
    "date": 20240514,
    "number": 0,
    "stream": "scda",
    "time": 1800,
    "step": [3, 6],
}

service = ecmwfapi.ECMWFService("mars")
service.execute(req, "_res.grib")

it fails with:

File /opt/homebrew/Caskroom/miniforge/base/envs/dev_ecc/lib/python3.10/site-packages/ecmwfapi/api.py:183, in robust.<locals>.wrapped(self, *args, **kwargs)
    181 while tries > 0:
    182     try:
--> 183         return func(self, *args, **kwargs)
    184     except HTTPError as e:
    185         if self.verbose:

File /opt/homebrew/Caskroom/miniforge/base/envs/dev_ecc/lib/python3.10/site-packages/ecmwfapi/api.py:386, in Connection.call(self, url, payload, method)
    383     self.done = True
    385 if "error" in self.last:
--> 386     raise APIException("ecmwf.API error 1: %s" % (self.last["error"],))
    388 if error:
    389     raise APIException("ecmwf.API error 2: %s" % (res,))

APIException: "ecmwf.API error 1: Invalid MARS request(s): Expected end of string, found u','  (at char 32), (line:1, col:33)"

This problem actually comes from using accumulation_period, which is not a valid MARS key. Unfortunately this is very hard to figure from error message so it should be improved.

What are the steps to reproduce the bug?

See above

Version

1.6.3

Platform (OS and architecture)

Any

Relevant log output

No response

Accompanying data

No response

Organisation

ECMWF