microsoft/PlanetaryComputer

Request exceeded the maximum allowed time

Ahleroy opened this issue ยท 6 comments

I have the following error with the python API :

pystac_client.exceptions.APIError: The request exceeded the maximum allowed time, please try again. If the issue persists, please contact planetarycomputer@microsoft.com.

Debug information for support: 20230716T154532Z-gdnzeuggn13zxf7nb0uwnmpz6c000000009000000001842g

Here is the subset of the code :

from pystac.extensions.eo import EOExtension as eo
import pystac_client
import planetary_computer
import time
import numpy as np
import rasterio
from rasterio import windows
from rasterio import features
from rasterio import warp
from PIL import Image

catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)

bounds = [-1.2867714015983258, 51.731613269987214,   -1.2148366398698462, 51.792129505211044]
lat1, lon1, lat2, lon2 = bounds

area_of_interest = {
    "type": "Polygon",
    "coordinates": [
        [
            [lat1, lon1],
            [lat2,lon1],
            [lat2, lon2],
            [lat1, lon2],
            [lat1, lon1],
        ]
    ],
}

date1 = "2022-09-01"
date2 = "2022-09-30"

time_of_interest = date1 + "/" + date2

t0 = time.time()
search = catalog.search(
    collections=["sentinel-2-l2a"],
    intersects=area_of_interest,
    datetime=time_of_interest,
)
t1 = time.time()
print(f"Search took {t1-t0} seconds")

items = search.item_collection()
print(f"Returned {len(items)} Items")

least_cloudy_item = min(items, key=lambda item: eo.ext(item).cloud_cover)

asset_href_visual = least_cloudy_item.assets["visual"].href
print(least_cloudy_item.id)

complete_asset = catalog.get_item(least_cloudy_item.id)

print("Start download")
t2 = time.time()
with rasterio.open(asset_href_visual) as ds:
    aoi_bounds = features.bounds(area_of_interest)
    warped_aoi_bounds = warp.transform_bounds("epsg:4326", ds.crs, *aoi_bounds)
    aoi_window = windows.from_bounds(transform=ds.transform, *warped_aoi_bounds)
    band_data_visual = ds.read(window=aoi_window)

print("End download")
img = Image.fromarray(np.transpose(band_data_visual, axes=[1, 2, 0]))
img.save("image_test.png")

Thanks for the report. Here's a slightly simpler reproducer:

import time

from pystac_client import Client


catalog = Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
)


def search():
    t0 = time.time()
    search = catalog.search(
        collections=["sentinel-2-l2a"],
        intersects={
            "type": "Point",
            "coordinates": [-1.28, 51.70],
        },
        datetime=["2022-09-01", "2022-09-30"],
    )

    items = search.item_collection()
    t1 = time.time()
    print(f"Search took {t1-t0} seconds")
    print(f"Returned {len(items)} Items")


for i in range(100):
    search()

We're looking into it and will post updates here.

One quick note: We do generally recommend adding retries to your HTTP requests.

https://pystac-client.readthedocs.io/en/stable/usage.html#configuring-retry-behavior has documentation on how to do that with pystac-client (though that doesn't currently retry POST requests, which is what's failing. See stac-utils/pystac-client#561).

FYI I'm having the same problem (also using Sentinel-2 L2A data and intersects in combination with a Point). Most of the requests fail suddenly (but not all).

We have the same problem since today, never before. We do retry. Sentinel-2-L2A as well, and SAR. It seems to be working intermittently?

Seems to be working again, thanks @TomAugspurger and @mmcfarland !

@mmcfarland deployed a change that seems to have resolved things. We'll keep monitoring it, but do let us know if you continue to see these errors.