cdsapi icon indicating copy to clipboard operation
cdsapi copied to clipboard

InsecureRequestWarning -- how to best resolve this warning/error?

Open monocongo opened this issue 5 years ago • 5 comments

When I make a request for a dataset via the Copernicus Climate Data Store API I get a series of InsecureRequestWarning messages such as the below:

/home/james/miniconda3/envs/climate/lib/python3.7/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

The request never returns with the requested dataset, and instead fails with a no data response error:

2019-05-11 14:14:13,199 INFO Request is failed
2019-05-11 14:14:13,201 ERROR Message: no data is available within your requested subset
2019-05-11 14:14:13,206 ERROR Reason:  Request returned no data
2019-05-11 14:14:13,210 ERROR   Traceback (most recent call last):
2019-05-11 14:14:13,214 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 49, in handle_request
2019-05-11 14:14:13,218 ERROR       result = cached(context.method, proc, context, *context.args, **context.kwargs)
2019-05-11 14:14:13,222 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
2019-05-11 14:14:13,226 ERROR       result = proc(context, *context.args, **context.kwargs)
2019-05-11 14:14:13,228 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 110, in __call__
2019-05-11 14:14:13,230 ERROR       return p(*args, **kwargs)
2019-05-11 14:14:13,233 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 59, in __call__
2019-05-11 14:14:13,234 ERROR       return self.proc(context, *args, **kwargs)
2019-05-11 14:14:13,236 ERROR     File "/home/cds/cdsservices/services/mars.py", line 338, in internal
2019-05-11 14:14:13,237 ERROR       return mars(context, request, **kwargs)
2019-05-11 14:14:13,237 ERROR     File "/home/cds/cdsservices/services/mars.py", line 61, in mars
2019-05-11 14:14:13,238 ERROR       raise NoDataException("Request returned no data", '')
2019-05-11 14:14:13,239 ERROR   cdsinf.exceptions.NoDataException: Request returned no data

The Python code I'm using to make this request:

days = list(map(lambda x: str(x).zfill(2), range(1, 32)))
months = list(map(lambda x: str(x).zfill(2), range(1, 13)))
years = list(map(lambda x: str(x).zfill(2), range(1980, 2019)))
api_request = {
    'area': '6.002/33.501/-5.202/42.283',
    'day': days,
    'format': 'netcdf',
    'month': months,
    'product_type': 'reanalysis',
    'time': ['00:00'],
    'variable': 'total_precipitation',
    'year': years
}
cds_client = cdsapi.Client()
cds_client.retrieve(
    'reanalysis-era5-pressure-levels-monthly-means',
    api_request,
    'kenya_rainfall_.nc'
)

I have followed the instructions in the link from the warning message and added the following code, to no avail:

import certifi
import urllib3
http = urllib3.PoolManager(
    cert_reqs='CERT_REQUIRED',
    ca_certs=certifi.where()
)

Please advise if this is a known issue with a resolution (sorry if so, I didn't find anything when searching for an answer to this), or if there are suggestions for a workaround. Thanks in advance.

monocongo avatar May 11 '19 18:05 monocongo

I have changed the verify property from 0 to 1 in my ~/.cdsapi file and this appears to have helped:

2019-05-11 14:32:52,680 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-pressure-levels-monthly-means
2019-05-11 14:32:53,229 INFO Request is queued

Hopefully the data will arrive soon...

monocongo avatar May 11 '19 18:05 monocongo

@monocongo did all the data come through? I was working on some helper functions that seem to be working which i can share if helpful?

tommylees112 avatar May 11 '19 19:05 tommylees112

The InsecureRequestWarning went away, apparently as a result of setting the verify property from 0 to 1, but now I get a no data available error:

2019-05-11 15:28:32,423 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-pressure-levels-monthly-means
2019-05-11 15:28:33,272 INFO Request is queued
2019-05-11 15:32:52,645 INFO Request is failed
2019-05-11 15:32:52,647 ERROR Message: no data is available within your requested subset
2019-05-11 15:32:52,649 ERROR Reason:  Request returned no data
2019-05-11 15:32:52,652 ERROR   Traceback (most recent call last):
2019-05-11 15:32:52,655 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 49, in handle_request
2019-05-11 15:32:52,658 ERROR       result = cached(context.method, proc, context, *context.args, **context.kwargs)
2019-05-11 15:32:52,663 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
2019-05-11 15:32:52,672 ERROR       result = proc(context, *context.args, **context.kwargs)
2019-05-11 15:32:52,675 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 110, in __call__
2019-05-11 15:32:52,676 ERROR       return p(*args, **kwargs)
2019-05-11 15:32:52,677 ERROR     File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 59, in __call__
2019-05-11 15:32:52,678 ERROR       return self.proc(context, *args, **kwargs)
2019-05-11 15:32:52,679 ERROR     File "/home/cds/cdsservices/services/mars.py", line 338, in internal
2019-05-11 15:32:52,680 ERROR       return mars(context, request, **kwargs)
2019-05-11 15:32:52,681 ERROR     File "/home/cds/cdsservices/services/mars.py", line 61, in mars
2019-05-11 15:32:52,682 ERROR       raise NoDataException("Request returned no data", '')
2019-05-11 15:32:52,683 ERROR   cdsinf.exceptions.NoDataException: Request returned no data

Is the verify option with value 0 in ~/.cdsapi file working for all other users? Or is setting the value to 1 a correct workaround for this issue? Also, the above no data available issue is separate from the originally mentioned issue, right?

monocongo avatar May 11 '19 21:05 monocongo

I am having the same issue. Was this resolved?

gewitterblitz avatar Oct 25 '21 18:10 gewitterblitz

Setting the parameter verify=True in cdsapi.Client seems to fix the InsecureRequestWarning error.

avnigo avatar Apr 05 '22 15:04 avnigo

Hi @monocongo , The failure here is because you have made a request that isn't valid and it returned no data. This is not an issue with the cdsapi software so I recommend that you request help from the CDS user support channel: https://cds.climate.copernicus.eu/cdsapp#!/usersupport They will help you with queries regarding the availability of data and issues regarding valid requests. Many thanks, Eddy

EddyCMWF avatar Feb 16 '23 12:02 EddyCMWF