Unable to access and download Sentinel-2 images from Python API with the standard code

467 views Asked by At
rec = POLYGON ((597843.23 2977645.792070312, 686175.1025585937 2977645.792070312, 686175.1025585937 3112308.537736816, 597843.23 3112308.537736816, 597843.23 2977645.792070312))
products = api.query(rec,
                     date = ('20191001', '20191031'),
                     platformname = 'Sentinel-2',          
                     cloudcoverpercentage = (0,40)
                    )

For the above code to download the sentinel-2 images, I am getting the following error:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/sentinelsat/sentinel.py in _load_subquery(self, query, order_by, limit, offset)

    394             json_feed = response.json()["feed"]
--> 395             if json_feed["opensearch:totalResults"] is None:
    396                
# We are using some unintended behavior of the server that a null is

KeyError: 'opensearch:totalResults'

During handling of the above exception, another exception occurred:

SentinelAPIError                          Traceback (most recent call last)
3 frames
/usr/local/lib/python3.6/dist-packages/sentinelsat/sentinel.py in _load_subquery(self, query, order_by, limit, offset)

    401             total_results = int(json_feed["opensearch:totalResults"])
    402         except (ValueError, KeyError):
403          raise SentinelAPIError("API response not valid. JSON decoding failed.", response)
    404 
    405         products = json_feed.get("entry", [])

SentinelAPIError: HTTP status 200 OK: API response not valid. JSON decoding failed.

I have read the docs and refereed to similar ques on the same error but unable to resolve the issue.

2

There are 2 answers

1
Ioannis Nasios On BEST ANSWER

Your polygon values are NOT coordinates

Blockquote

rec = POLYGON ((597843.23 2977645.792070312, 686175.1025585937 2977645.792070312, 686175.1025585937 3112308.537736816, 597843.23 3112308.537736816, 597843.23 2977645.792070312))

You need to describe your polygon in longtitude latitude values.

0
M.Ahmadkhani On

Use this code and download using sentinelsat Python API:

from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
import geopandas as gpd
foot = gpd.read_file('extent.shp')
foot = foot.geometry.to_wkt()
api = SentinelAPI('USERNAME', 'PASSWORD', 'https://scihub.copernicus.eu/dhus')
products = api.query(foot[0], date=('20210615', '20210720'), platformname='Sentinel-2', cloudcoverpercentage=(0, 10), limit=1)
api.download_all(products)

Please note that the extent.shp should be a simple 4-5 vertex polygon showing your location of interest.