Hi
I’m trying to get some simple data from sentinel 2 dataset. Just copied this simple request script, but it still wants me to put some headers and I don’t know where to do it.
Script looks like this:
from sentinelhub import CRS, BBox, MimeType, SentinelHubRequest, SHConfig
from sentinelhub import DataCollection
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
Write your credentials here if you haven’t already put them into config.toml
CLIENT_ID = “…”
CLIENT_SECRET = “…”
config = SHConfig()
if CLIENT_ID and CLIENT_SECRET:
config.sh_client_id = CLIENT_ID
config.sh_client_secret = CLIENT_SECRET
config.sh_token_url = “https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token”
config.sh_base_url = “https://sh.dataspace.copernicus.eu”
client = BackendApplicationClient(client_id=config.sh_client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=config.sh_token_url, client_id=config.sh_client_id, client_secret=config.sh_client_secret, include_client_id=True)
print(token[“access_token”])
Columbia Glacier, Alaska
glacier_bbox = BBox((-147.8, 60.96, -146.5, 61.38), crs=CRS.WGS84)
glacier_size = (700, 466)
time_interval = “2020-07-15”, “2020-07-16”
evalscript_true_color = “”"
//VERSION=3
function setup() {
return {
input: [{
bands: [“B02”, “B03”, “B04”]
}],
output: {
bands: 3
}
};
}
function evaluatePixel(sample) {
return [sample.B04, sample.B03, sample.B02];
}
“”"
request = SentinelHubRequest(
evalscript=evalscript_true_color,
input_data=[
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L2A,
time_interval=time_interval,
)
],
responses=[SentinelHubRequest.output_response(“default”, MimeType.PNG)],
bbox=glacier_bbox,
size=glacier_size,
config=config,
)
image = request.get_data()[0]
And I’m getting this error as below. Token is generated as should as I can print this.
Server response: “{“status”: 401, “reason”: “Unauthorized”, “message”: “You are not authorized! Please provide a valid access token within the header [Authorization: Bearer ] of your request.”, “code”: “COMMON_UNAUTHORIZED”}”