Error 400: Bad Request --> RENDERER_EXCEPTION

Hi,

i am new with sentinel-hub and i need some help. I am trying to send a request with c# and .net but no luck.

This is my code. Any help will be apreciated, thanks:

JavaScriptSerializer js = new JavaScriptSerializer();

            string clientID =xxxxxx;
            string ClientSecret = xxxxx;


            string APIUrl = ST_e03eb2a3ca5042cbafc7b8cad022a157.Properties.Resources.URL;

            HttpClient client = new HttpClient(handler: httpClientHandler, disposeHandler: true);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ST_e03eb2a3ca5042cbafc7b8cad022a157.Properties.Resources.token);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/tar"));

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;


            var request = new HttpRequestMessage();
            request.Method = HttpMethod.Post;
            request.RequestUri = new Uri(APIUrl);


            var content = new MultipartFormDataContent();

            content.Headers.ContentType.MediaType = "multipart/form-data";
            
            var dataContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("request", js.Serialize(fillInput())),
                new KeyValuePair<string, string>("evalscript", ST_e03eb2a3ca5042cbafc7b8cad022a157.Properties.Resources.evalscript)
            });


            content.Add(dataContent);

            request.Content = content;
            var header = new ContentDispositionHeaderValue("form-data");
            request.Content.Headers.ContentDisposition = header;

            var response = client.PostAsync(request.RequestUri.ToString(), request.Content);
            var result = response.Result;

And the parameters i send are two, input and evalscript.

The input parameter i serialize from an object that has something like this:

{"input": {
    "bounds": {
      "properties": {
        "crs": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              12.480661,
              41.965872
            ],
            [
              12.523909,
              41.96817
            ],
            [
              12.553084,
              41.931401
            ],
            [
              12.525968,
              41.906365
            ],
            [
              12.491645,
              41.894355
            ],
            [
              12.449084,
              41.896911
            ],
            [
              12.433295,
              41.926292
            ],
            [
              12.442219,
              41.950043
            ],
            [
              12.480661,
              41.965872
            ]
          ]
        ]
      }
    },
    "data": [{
      "type": "landsat-ot-l2",
      "dataFilter": {
        "timeRange": {
          "from": "2020-07-01T00:00:00Z",
          "to": "2020-07-31T00:00:00Z"
        }
      }
    }]
  },
  "output": {
    "width": 512,
    "height": 512,
    "responses": [{
      "identifier": "default",
      "format": {
        "type": "image/tiff"
      }
    }]
  }
}
}

and the evalscript has the string with the functions:

function setup() { return { input: [{ bands: ['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B10', 'BQA'] }], output: { id: 'default', bands: 9, sampleType: SampleType.UINT16 } } } function evaluatePixel(sample) {  return [10000 * sample.B01, 10000 * sample.B02, 10000 * sample.B03, 10000 * sample.B04, 10000 * sample.B05, 10000 * sample.B06, 10000 * sample.B07, sample.B10, sample.BQA] }

thanks in advance

Hey,
by the parameters, I assume you are making requests to the Processing API.

The parameters themselves are ok - when making a request with the provided parameters in Requests builder (copying json object to the correct position in the Request Preview text field and clicking parse and evalscript into the Evalscript text field), the data is correctly returned.

It seems that the parameters are not correctly sent to the server.
i.e. I get RENDERER_EXCEPTION when I provide an empty string for the evalscript parameter.

Can you check the message of the returned error? The error is a json object that looks like

{
  "error": {
    "status": 400,
    "reason": "Bad Request",
    "message": "...",
    "code": "RENDERER_EXCEPTION"
  }
}

I suspect that the problem is the way the parameters are provided.
If possible, I suggest providing parameters as one (serialized) json object, like it’s shown in the API reference.

{
  "input": {...},
  "output": {...},
  "evalscript": "string"
}

I think it can be done similarly to this

var requestData = ...; // json object containing input, output and evalscript
string serializedJson = JsonSerializer.Serialize(requestData);
var content = new StringContent(serializedJson, Encoding.UTF8, "application/json");
request.Content = content;

In this case, the multipart/form-data header isn’t needed.

Hope this helps.
Cheers

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