E.g., will something as simple as this do? Or should I include some logic within the c.retrieve method for "day", e.g., to handle different length months, and if so then how? Additionally, can you explain why my previous script was seeing apparently arbitrary timeouts once in a while and, so, subsequent crashes? Is that a function of user demand on your end resulting in variable length (temporally, wall clock) retrievals and, so, occasional (and unpredictable) slower retrievals that exceed some threshold time length and the error?
import cdsapi
c = cdsapi.Client()
for year in range(2015,2020):
for mon in range(1,13):
if (mon < 10):
themon="0"+str(mon)
else:
themon=str(mon)
c.retrieve("reanalysis-era5-single-levels", {
"product_type": "reanalysis",
"format": "netcdf",
"variable": "runoff",
"year": str(year),
"month": themon,
# Assume cdsapi will skip extraneous days in shorter months without a problem...
"day": ["01","02","03","04","05","06","07","08","09","10","11",
"12","13","14","15","16","17","18","19","20","21","22",
"23","24","25","26","27","28","29","30","31"],
"time": ["00","01","02","03","04","05","06","07","08","09","10","11",
"12","13","14","15","16","17","18","19","20","21","22","23"],
}, "output."+str(year)+str(themon)+".nc")