Tiff image request

Hi everyone!
I having a problem with a Tiff image python request: I developed a Google Colab in which the code works fine, then I move the same code on a local python scritp. The request give me http response code 400.

I attache the 2 bodies:
COLAB ONE: it works

{'input': 
{'bounds': {'properties': {'crs': 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'},
   'geometry': {'type': 'Polygon',
    'coordinates': [[[12.51388888888889, 43.1780556],
      [12.515277777777778, 43.1786111],
      [12.515277777777778, 43.1788889],
      [12.516944444444444, 43.1788889],
      [12.517222222222223, 43.1786111],
      [12.516944444444444, 43.1786111],
      [12.516666666666667, 43.1780556],
      [12.516666666666667, 43.1777778],
      [12.514722222222222, 43.1769444],
      [12.51388888888889, 43.1780556]]]}},
  'data': [{'type': 'sentinel-2-l2a',
    'dataFilter': {'timeRange': {'from': '2023-05-01T00:00:00Z',
      'to': '2023-05-30T23:59:59Z'}}}]},
 'output': {'width': 512,
  'height': 512,
  'responses': [{'identifier': 'default', 'format': {'type': 'image/tiff'}}]},
 'evalscript': '\n    function setup() {\n      return {\n        input: [{\n          bands: [\n            "B04",\n            "B08",\n            "dataMask"\n          ]\n        }],\n        output: {\n            bands: 1,\n            sampleType: SampleType.FLOAT32\n        }\n      }\n    }\n\n    function evaluatePixel(samples) {\n      let val = index(samples.B08, samples.B04);\n      val = Math.round((val+1)*127.5)\n      return [val];\n    }\n  '}

LOCAL PYTHON SCRIPT ONE: it doesn’t work

{
    "input": {
        "bounds": {
            "properties": {
                "crs": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            8.056948180237876,
                            44.551907115706214
                        ],
                        [
                            8.057669511725484,
                            44.55280107711689
                        ],
                        [
                            8.058673103360416,
                            44.55234378318776
                        ],
                        [
                            8.058460805129952,
                            44.55236097475386
                        ],
                        [
                            8.05824126945981,
                            44.55236613222271
                        ],
                        [
                            8.058074808347284,
                            44.55234894065812
                        ],
                        [
                            8.057867335076601,
                            44.55221828460141
                        ],
                        [
                            8.057623674607543,
                            44.55202917663137
                        ],
                        [
                            8.057507875572743,
                            44.551932903246936
                        ],
                        [
                            8.057343826940107,
                            44.55188132815406
                        ],
                        [
                            8.056943355278092,
                            44.55190023902676
                        ],
                        [
                            8.056948180237876,
                            44.551907115706214
                        ]
                    ]
                ]
            }
        },
        "data": [
            {
                "type": "sentinel-2-l2a",
                "dataFilter": {
                    "timeRange": {
                        "from": "2024-02-04 09:15:02Z",
                        "to": "2024-02-10 09:15:02Z"
                    }
                }
            }
        ]
    },
    "output": {
        "width": 512,
        "height": 512,
        "responses": [
            {
                "identifier": "default",
                "format": {
                    "type": "image/tiff"
                }
            }
        ]
    },
    "evalscript": "function setup() {\n            return {\n           
     input: [
        {\n                    bands: [\n                        "B04",\n                        "B08",\n                        "dataMask"\n
            ]\n
        }
    ],\n                output: {\n                    bands: 1,\n                    sampleType: SampleType.FLOAT32\n
    }\n
}\n
}\n        function evaluatePixel(samples) {\n            let savi = 1.5 * (samples.B08 - samples.B04) / (samples.B08 + samples.B04 + 0.5);\n            return [savi
];\n
}"}

I cannot see any relevant differences! Help me!

Hi,

A 400 error usually indicates an issue with your credentials. I suggest you double check the credentials in your local environment. The docs on setting on Authentication can be found here

1 Like

Sure… I checked cliendtID client secret, token url, I receive the new token, these 3 lines of code seeems to be ok (python code):

client = BackendApplicationClient(client_id=client_id)
 oauth = OAuth2Session(client=client)
 token = oauth.fetch_token(token_url=url, client_secret=client_secret, include_client_id=True)['access_token']

Then i perform the post request using the bodies at the top, always 400 with python script, always 200 with python google colab. I have no idea about the reasons!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.