sentinel-hub / sentinelhub-py

Download and process satellite imagery in Python using Sentinel Hub services.
http://sentinelhub-py.readthedocs.io/en/latest/
MIT License
798 stars 243 forks source link

[HELP] Always (invalid_client) Invalid client or Invalid client credentials #534

Closed geoexploring closed 1 month ago

geoexploring commented 1 month ago

When I use the official example (as shown in the Python code below), I consistently encounter the following error: oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) Invalid client or Invalid client credentials . Despite changing the OAuth clients twice, the issue persists.

I registered with Sentinelhub, not the Copernicus Data Space Ecosystem, and I am using sentinelhub == 3.10.2 with python == 3.9.5 .

Can anyone help me resolve this problem? Thank you very much.

from sentinelhub import SHConfig

from sentinelhub import (
    CRS,
    BBox,
    DataCollection,
    MimeType,
    SentinelHubRequest,
    bbox_to_dimensions,
)

if __name__ == '__main__':

    config = SHConfig()
    config.instance_id = 'USER INSTANCE ID'
    config.sh_client_id = 'sh_client_id'
    config.sh_client_secret = 'sh_client_secret'

    config.save()

    if not config.sh_client_id or not config.sh_client_secret:
        print("Warning! To use Process API, please provide the credentials (OAuth client ID and client secret).")

    betsiboka_coords_wgs84 = (46.16, -16.15, 46.51, -15.58)

    resolution = 60
    betsiboka_bbox = BBox(bbox=betsiboka_coords_wgs84, crs=CRS.WGS84)
    betsiboka_size = bbox_to_dimensions(betsiboka_bbox, resolution=resolution)

    print(f"Image shape at {resolution} m resolution: {betsiboka_size} pixels")

    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_true_color = SentinelHubRequest(
        evalscript=evalscript_true_color,
        input_data=[
            SentinelHubRequest.input_data(
                data_collection=DataCollection.SENTINEL2_L1C,
                time_interval=("2020-06-12", "2020-06-13"),
            )
        ],
        responses=[SentinelHubRequest.output_response("default", MimeType.PNG)],
        bbox=betsiboka_bbox,
        size=betsiboka_size,
        config=config,
    )

    true_color_imgs = request_true_color.get_data()

When I use the Copernicus Data Space Ecosystem client, I met the following error: 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"}" .

maximlamare commented 1 month ago

Hi @geoexploring ,

I would kindly ask you to post this request in the community forum as it is monitored by more people that will be able to provide you with an answer quickly.

Thanks in advance!

geoexploring commented 1 month ago

@maximlamare, thank you. I have posted in this link, but they repeatedly direct me to the documentation, which is not helpful.

geoexploring commented 1 month ago

The problem is solved. I just moved the code to run on an Ubuntu system.

I’m not sure if that was the main reason.