I am a Copernicus Data Space Ecosystem user and am trying to download Sentinel-2 L1C data for a specific region in France (200 km²) between 2015 and 2024. I am using the Sentinel Hub Python library to achieve this.
The code works fine when I request data visualization without saving it (using request_all_bands.get_data()
). However, when I try to download the data in TIFF format using request_all_bands.get_data(save_data=True)
or request_all_bands.save_data()
, I encounter an error:
DownloadFailedException: Failed to download from:
https://services.sentinel-hub.com/api/v1/process
with HTTPError:
401 Client Error: Unauthorized for url: https://services.sentinel-hub.com/api/v1/process
Server response: "{"status": 401, "reason": "Unauthorized", "message": "You are not authorized! Please provide a valid access token within the header [Authorization: Bearer <accessToken>] of your request.", "code": "COMMON_UNAUTHORIZED"}"
Questions:
- Is downloading data for personal, non-commercial use restricted for Copernicus Data Space Ecosystem users?
- If downloading data is allowed, what steps do I need to take to successfully download Sentinel-2 L1C data in TIFF format for my analysis?
Code Snippet:
from sentinelhub import SHConfig
config = SHConfig()
config.sh_client_id = '***********'
config.sh_client_secret = '**********'
config.sh_base_url = 'https://sh.dataspace.copernicus.eu'
config.sh_token_url = 'https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token'
import datetime
import os
import matplotlib.pyplot as plt
import numpy as np
from sentinelhub import (
CRS,
BBox,
DataCollection,
DownloadRequest,
MimeType,
MosaickingOrder,
SentinelHubDownloadClient,
SentinelHubRequest,
bbox_to_dimensions,
)
# Create BBox
bbox = ....
resolution = 10
size = bbox_to_dimensions(bbox, resolution=resolution)
evalscript_all_bands = """
//VERSION=3
function setup() {
return {
input: [{
bands: ["B01","B02","B03","B04","B05","B06","B07","B08","B8A","B09","B10","B11","B12"],
units: "DN"
}],
output: {
bands: 13,
sampleType: "INT16"
}
};
}
function evaluatePixel(sample) {
return [sample.B01,
sample.B02,
sample.B03,
sample.B04,
sample.B05,
sample.B06,
sample.B07,
sample.B08,
sample.B8A,
sample.B09,
sample.B10,
sample.B11,
sample.B12];
}
"""
request_all_bands = SentinelHubRequest(
data_folder="test_dir",
evalscript=evalscript_all_bands,
input_data=[
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L1C,
time_interval=("2020-06-01", "2020-06-30"),
mosaicking_order=MosaickingOrder.LEAST_CC,
)
],
responses=[SentinelHubRequest.output_response("default", MimeType.TIFF)],
bbox=bbox,
size=size,
config=config,
)
%%time
all_bands_img = request_all_bands.get_data(save_data=True)
Additional Information:
I have confirmed my client ID and secret are set correctly in the SHConfig
object.
I have verified that my Copernicus Data Space Ecosystem account is active.
I would appreciate any insights or solutions to help me download Sentinel-2 L1C data using my free Copernicus Data Space Ecosystem account.
Thank you for your support!