Repository navigation
Closed
Description
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")Metadata
Metadata
Assignees
Labels
No labels
Activity
TomAugspurger commentedon Jul 17, 2023
Thanks for the report. Here's a slightly simpler reproducer:
We're looking into it and will post updates here.
TomAugspurger commentedon Jul 17, 2023
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
POSTrequests, which is what's failing. See stac-utils/pystac-client#561).mhelleis commentedon Jul 17, 2023
FYI I'm having the same problem (also using Sentinel-2 L2A data and
intersectsin combination with aPoint). Most of the requests fail suddenly (but not all).ZirconCode commentedon Jul 17, 2023
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?
ZirconCode commentedon Jul 17, 2023
Seems to be working again, thanks Tom Augspurger (@TomAugspurger) and Matt McFarland (@mmcfarland) !
TomAugspurger commentedon Jul 17, 2023
Matt McFarland (@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.
KBodolai commentedon May 8, 2024
I've stumbled upon the same issue when trying to fetch some landsat time series:
Which gives the error below:
Details
The error goes away if I try some other paths/rows (e.g. changing the path to 168) or if I do a much shorter time period (e.g.
2023-01-01/2024-01-01).TomAugspurger commentedon May 8, 2024
A couple quick notes:
landsat:wrs_pathandlandsat:wrs_rowas aquerycondition is helpful, but not enough. We need to add an index on those in the database, which should speed things up a lot (Antimeridian-crossing Items and Searching For Them #296).KBodolai commentedon May 17, 2024
Thanks Tom, very informative as always!
I used to have a spatial search with a bounding box in that snippet that failed as well, very interesting about your first point!
I hadn't come across the bulk item access, I'll play around with that now :)
Ethan-Chen421 commentedon Oct 18, 2024
import json
import pystac_client
import planetary_computer
from pystac_client import Client, Modifiable
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.http import JsonResponse
from urllib.parse import urlparse
@csrf_exempt # 使得视图可以跳过CSRF验证,对于接收外部API请求时有用
@require_POST
def search_NDVI(request):
if request.method == 'POST':
start_date = request.POST.get('start_date')
end_date = request.POST.get('end_date')
cloud_cover = request.POST.get('cloud_cover')
time_of_interest = f'{start_date}/{end_date}'
geojson_str = request.POST.get('geojson')
import json
import pystac_client
import planetary_computer
from pystac_client import Client, Modifiable
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.http import JsonResponse
from urllib.parse import urlparse
@csrf_exempt
@require_POST
def search_NDVI(request):
if request.method == 'POST':
start_date = request.POST.get('start_date')
end_date = request.POST.get('end_date')
cloud_cover = request.POST.get('cloud_cover')
time_of_interest = f'{start_date}/{end_date}'
geojson_str = request.POST.get('geojson')
I also encountered the same problem when I integrated the functionality into Django
Wrong content:pystac_client.exceptions.apierror: the request exceeded the maximum allowed time, please try again. if the issue persists, please contact planetarycomputer@microsoft.com.
Pistonamey commentedon Jan 23, 2026
Getting the same issue for:
def load_terraclimate_dataset():
"""
Load TerraClimate dataset from Microsoft Planetary Computer.
"""
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=pc.sign_inplace,
)
collection = catalog.get_collection("terraclimate")
asset = collection.assets["zarr-abfs"]