1

I have been attempting to get data via sentinel2 API with python and I have been unable to get data via geojson format. It keeps throwing a "SentinelAPIError: HTTP status 200 OK: API response not valid. JSON decoding failed."

I followed the documentation thoroughly yet I kept on getting the same error. I could get Point data but I am unable to get geojson data.

I will appreciate you assistance with this. Here is the snippet of the code. "

    if self.boundary.endswith('.geojson'):
        
        
        footprint = geojson_to_wkt(read_geojson(self.boundary))

        
        products = api.query(footprint,
                             
                     date=(self.start_date,self.end_date),

                     platformname = 'Sentinel-2',

                     cloud_cover= (0,self.cloud_cover))
        

        products_gdf = api.to_geodataframe(products)

"

Here is the Error.


/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)
4 fr
/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.

Thank you.

Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
Philip-kio
  • 11
  • 1
  • 1

2 Answers2

0

It seems that your.geojson file can't be decoded. First check the encoding - language of file been created. If this doesn't help,

check that your .geojson is like the format below:

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [ 23.642578125, 37.93553306183642 ], [ 23.8018798828125, 37.93553306183642 ], [ 23.8018798828125, 38.026458711461245 ], [ 23.642578125, 38.026458711461245 ], [ 23.642578125, 37.93553306183642 ] ] ] } } ] }

You can produce a .geojson file fast in this page.

Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
  • 1
    Thank you for your response. Turns out my problem was that I did not use the right variable that was created for the API. I wrote `self.cloud_cover` when it was meant to be `cloudcoverpercentage`. – Philip-kio Jan 21 '21 at 08:02
0

Turns out my problem was that I did not use the right variable that was created for the API. I wrote self.cloud_cover when it was meant to be self.cloudcoverpercentage. Which I skipped in the documentation.

Philip-kio
  • 11
  • 1
  • 1