I am getting the error 403: {“error”:{“status”:403,“reason”:“Forbidden”,“message”:“Invalid or expired account.”,“code”:“COMMON_INSUFFICIENT_PERMISSIONS”}}
I bought the exploration package and should be therefore able to use the API, but still cant.
I already tried two times to delete and recreate OAuth id and secret.
Code:
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
# Your client credentials
client_id = 'secret'
client_secret = 'secret'
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(
token_url='https://services.sentinel-hub.com/oauth/token',
client_id=client_id,
client_secret=client_secret
)
resp = oauth.get("https://services.sentinel-hub.com/oauth/tokeninfo")
print(resp.content)
def sentinelhub_compliance_hook(response):
response.raise_for_status()
return response
oauth.register_compliance_hook("access_token_response", sentinelhub_compliance_hook)
evalscript = """
//VERSION=3
function setup() {
return {
input: ["B02", "B03", "B04"],
output: { bands: 3 },
}
}
function evaluatePixel(sample) {
return [2.5 * sample.B04, 2.5 * sample.B03, 2.5 * sample.B02]
}
"""
request = {
"input": {
"bounds": {
"properties": {"crs": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"},
"bbox": [
[13.2042218, 51.1035219], # Punkt 1 (lng, lat)
[13.8472199, 51.1035219], # Punkt 2 (lng, lat)
[13.8472199, 51.0362128], # Punkt 3 (lng, lat)
[13.2042218, 51.0362128], # Punkt 4 (lng, lat)
[13.2042218, 51.1035219] # Punkt 1 (lng, lat) - geschlossen
],
},
"data": [
{
"type": "sentinel-2-l2a",
"dataFilter": {
"timeRange": {
"from": "2023-10-31T00:00:00Z",
"to": "2023-10-01T00:00:00Z",
}
},
}
],
},
"output": {
"width": 512,
"height": 512,
},
"evalscript": evalscript,
}
url = "https://sh.dataspace.copernicus.eu/api/v1/process"
response = oauth.post(url, json=request, headers={"Accept": "image/tiff"})
# saving response
import os
output_directory = 'database/'
output_filename = 'sentinel_output.tiff'
if not os.path.exists(output_directory):
os.makedirs(output_directory)
output_path = os.path.join(output_directory, output_filename)
if response.status_code == 200:
with open(output_path, 'wb') as file:
file.write(response.content)
print(f'Datei gespeichert: {output_path}')
else:
print(f"Error: {response.status_code}")
print(response.text)