Server response: "Invalid request" (400 Client Error)

Hello,

iI’m using WMS request in order to download images from specific bbox.
the script runs on different shapefiles from table, create bbox for them and then supose to download the images to a folder. The script is able to run on some of the bboxes but there is one it fails to download images with the following error:

with HTTPError:
400 Client Error: Bad Request for url: https://services.sentinel-hub.com/ogc/wms/e034c959-4b7b-4562-MASKED?SERVICE=wms&WARNINGS=False&MAXCC=100.0&BBOX=43.2967163924%2C24.75831009329897%2C43.57486571060041%2C25.0479801973&FORMAT=image%2Ftiff&CRS=EPSG%3A4326&TIME=2020-05-03T07%3A28%3A19Z%2F2020-05-03T11%3A28%3A19Z&WIDTH=2422&HEIGHT=3030&LAYERS=NDVI_MASK_CLOUD&REQUEST=GetMap&VERSION=1.3.0
Server response: “Invalid request”

The bbox size is less than 5000X5000 :

bbox_size[0]
>>>
2422
bbox_size[1]
>>>3030

Is there any way to understand what is the source of the error? From th elink I can only understand that the request is invalid, yet, is working perfectly for other bboxes.

This is the full script:

import unicodedata
plt.rcParams.update({'figure.max_open_warning': 0})


count=0
for i,x,bbox in zip(shapes['geometry'],shapes['Name'],shapes['bb']):
    print(x)
    
    
    bbox = BBox(bbox, crs=CRS.WGS84)
    bbox_size = bbox_to_dimensions(bbox, resolution=10)
    
    
    wms_bands_request = WmsRequest(
        data_collection=DataCollection.SENTINEL2_L2A,
        layer='NDVI_MASK_CLOUD',
        bbox=bbox,
        time=time_interval,
        width=bbox_size[0],
        height=bbox_size[1],
        image_format=MimeType.TIFF,
        time_difference=datetime.timedelta(hours=2),#get one image when there is small time differences between them
        config=config
    )
    dates= wms_bands_request.get_dates()
    
    for d in dates:
        try:
            wms_bands_request = WmsRequest(
            data_collection=DataCollection.SENTINEL2_L2A,
            data_folder='imgs1/{}/{}'.format(x,str(d)),
            layer='NDVI_MASK_CLOUD',
            bbox=bbox,
            time=d,
            width=bbox_size[0],
            height=bbox_size[1],
            image_format=MimeType.TIFF,
            time_difference=datetime.timedelta(hours=2),#get one image when there is small time differences between them
            config=config
            )
            
            wms_bands_img = wms_bands_request.get_data(save_data=True)
        except Exception as e: 
            print(e)
            continue

The goal: to understand why this specific bbox dowsn’t allow to download the images and to solve it :slight_smile:

Hi @reutkeller ,

I tested your WMS requests and it fails for this specific bbox because the requested image exceeds the maximum size of 2500x2500 pixels.

The bbox_to_dimensions(bbox, resolution) function calculates the width and height in pixels for a given bbox and the desired image resolution. The bbox is simply too large for the request, so you could go with one of the following options:

  • adjust the resolution (I assume this is not the best option for your workflow)
  • reduce the bbox size (highly depends on your AOI)
  • split your bbox in smaller parts and run several requests for the AOI

For the last option, please have a look at the BBoxSplitter function from the sentinelhub-py large area utilities.

Unlike our Process API, the OGC API currently doesn’t provide a more detailed error message. I will check with my colleagues if we can improve this.

Cheers and enjoy your weekend,
Max

1 Like