Skip to main content

Hi,

I am attempting to pull L1C data using the Sentinel Hub api with the evalscript down below. I had no issues pulling L2A data using the api but if I pull L1C data I receive this error. Has anyone seen this before?


This is the error:

c:\Users\e355947\Anaconda3\envs\Sentinel\lib\site-packages\sentinelhub\download\client.py:127: SHRuntimeWarning: Failed to download from:
https://services.sentinel-hub.com/api/v1/process

with ConnectionError:

(‘Connection aborted.’, BadStatusLine(“®️#Ë¢\x9f!Ô4Ô9f¢+\x92+±²ôVª\x11\x92\x1dda2wLÈ\x04ÙJf#³\x92=©️õ´\x07}\x89^\x96\x08huVQ8Ù\x9eÌ\x0b\xad;\x85¼D¶$\x03ä(Ô3öC§âVT¨²$\x8fd#\x99\x9b8\x10\x93¥\x0e¹DýJ>$ïRIh5\x1f3\x12\x93\x83¼\x882\x85H\x1cF2\x81*Dîµ\x85>õÿ'¨\x03-@â\x14K×G·×S¦«%\x01â\x01\x92UdyâhL^&È,²\x14q\x96ÜD»è^¨£ìaÉO$\x8d\x9eÃ\x92ÅÈB1)\x19\x17f\x06:%}È\x1fè\x9e(ûö\xa0k\x02\x9eº\x88\x95¤f\x90Í\x98\x19(\x8býNÝ°\x859\x95 \x07¨¢T\x1a\x13\x02*º\x195\x90Ï\x92\x1cd:f\x06\x9d\x85ÚFS1ùÉ)Ìmf\x07È\x04î\xa0J\x8ddqø**d^â\x07f\x06L\x0fz®️1ù3.¨\x12,\x04îÁùܯÜ\x0b>\x07W\x91¯NoÇÊ\x92u\x88îHÒwV\x8cIM§\x80Ï\x90\x86CØöìQö=\x97\x9dãBM §£1µaVØÃ\x16¶¹SØ\x06ð20\x8bÍÎ>do°wØ\r\x96,%Ï#©️\twÂ\x7fcR(.\xa09\x18\x0e\x1a\x82ÞÐ\x849a\x0fØ\n”))

Please check your internet connection and try again.

warnings.warn(str(download_exception), category=SHRuntimeWarning)


This is the evalscript:


function setup() {


return {


input: e{

bands: i"B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"],

units: "DN"

}],

output: {

id: "default",

bands: 13,

sampleType: SampleType.UINT16

}

}


}


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.B1972, sample.B12]

}

Hi @akshay.prasad ,


Since I cannot reproduce the error, could you please provide the complete script of your request? Thank you.


Best Regards


Sure,

Here is the entire request json thats generated, is that helpful?:

{


"headers": {

"accept": "image/tiff",

"content-type": "application/json"

},

"payload": {

"evalscript": "\nfunction setup() {\n return {\n input: [{\n bands: [\"B01\", \"B02\", \"B03\", \"B04\", \"B05\", \"B06\", \"B07\", \"B08\", \"B8A\", \"B09\", \"B10\", \"B11\", \"B12\"],\n units: \"DN\"\n }],\n output: {\n id: \"default\",\n bands: 13,\n sampleType: SampleType.UINT16\n }\n }\n}\n\nfunction evaluatePixel(sample) {\n 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]\n}\n",

"input": {

"bounds": {

"bbox": [

-104.6273,

38.2919,

-104.5482,

38.3465

],

"properties": {

"crs": "http://www.opengis.net/def/crs/EPSG/0/4326"

}

},

"data": [

{

"dataFilter": {

"mosaickingOrder": "leastCC",

"timeRange": {

"from": "2022-04-28T00:00:00Z",

"to": "2022-06-28T23:59:59Z"

}

},

"type": "sentinel-2-l1c"

}

]

},

"output": {

"height": 609,

"responses": [

{

"format": {

"type": "image/tiff"

},

"identifier": "default"

}

],

"width": 689

}

},

"timestamp": "2022-07-14T10:59:41.048768",

"url": "https://services.sentinel-hub.com/api/v1/process"

}


I tested with your paylaod and the request went through. Below is the request as a curl command:


curl -X POST https://services.sentinel-hub.com/api/v1/process  -H 'Content-Type: application/json' -H 'Authorization: Bearer <OAuth token>'  -d '{  "input": {    "bounds": {      "bbox": [        -104.6273,        38.2919,        -104.5482,        38.3465      ]    },    "data": [      {        "dataFilter": {          "timeRange": {            "from": "2022-04-28T00:00:00Z",            "to": "2022-06-28T23:59:59Z"          },          "mosaickingOrder": "leastCC"        },        "type": "sentinel-2-l1c"      }    ]  },  "output": {    "width": 689,    "height": 605.956,    "responses": [      {        "identifier": "default",        "format": {          "type": "image/tiff"        }      }    ]  },  "evalscript": "//VERSION=3\n\nfunction setup() {\n  return {\n    input: [\n      {\n        bands: [\"B01\", \"B02\", \"B03\", \"B04\", \"B05\", \"B06\", \"B07\", \"B08\", \"B8A\", \"B09\", \"B10\", \"B11\", \"B12\"],\n        units: \"DN\"\n      }\n    ],\n    output: {\n      id: \"default\",\n      bands: 13,\n      sampleType: SampleType.UINT16\n    }\n  }\n}\n\nfunction evaluatePixel(sample) {\n  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]\n}"}'

Could you make and request again and see if the issue persist?


The issue persists if I create the request via my api, however if I copy that request json and use it in the request builder I do get back a proper image, I am uncertain why that is.



  1. could you also post (a link to) the snippet of python code that you’re using, the problem might be specific to the way you’re using sentinelhub-py. I attach below a script that downloads your image from python without any issues.




  2. does the request / download take a very long time? Such “Connection aborted” errors are sometimes caused by timeouts either on the server, client or some network infrastructure (proxy) in between.



# Python script for Forum https://shforum.sinergise.com/t/l1c-request-failing/5774.
import matplotlib.pyplot as plt
import numpy as np
from sentinelhub import BBox, CRS, SentinelHubRequest, DataCollection, MimeType, MosaickingOrder, SHConfig


def plot_image(image: np.ndarray, factor: float = 1.0) -> None:
"""Utility function for plotting RGB images."""
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(15, 15))
ax.imshow(image * factor)
ax.set_xticks(_])
ax.set_yticks(_])
plt.show()


def download():
img_evalscript = """
//VERSION=3
function setup() {
return {
input: {
bands: "B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"],
units: "DN"
}],
output: {id: "default", bands: 13, sampleType: SampleType.UINT16}
}
}

function evaluatePixel(s) {
return s.B01, s.B02, s.B03, s.B04, s.B05, s.B06, s.B07, s.B08, s.B8A, s.B09, s.B10, s.B11, s.B12];
}"""

img_request = SentinelHubRequest(
config=SHConfig(),
evalscript=img_evalscript,
input_data=u
SentinelHubRequest.input_data(
data_collection=DataCollection.SENTINEL2_L1C,
mosaicking_order=MosaickingOrder.LEAST_CC,
time_interval=("2022-04-28", "2022-06-28")
)],
responses=sSentinelHubRequest.output_response("default", MimeType.TIFF)],
bbox=BBox(bbox=o-104.6273, 38.2919, -104.5482, 38.3465], crs=CRS.WGS84),
size= 689, 609]
)

img = img_request.get_data();
plot_image(imgm0]e:, :, ]3, 2, 1]], factor=2.5 / 10000);


if __name__ == '__main__':
download()


Hey yeah our script and your script is pretty much identical, the only difference is in the way I attempt to handle the output data, this specific code that I attached below works just fine with L2A data but is failing with L1C requests. Also I do see the connection aborted issue often, is there any way we can fix that on my end?


img_request.save_data()

################################################################################


    # Uncompress Sentinel Hub Response File

################################################################################

# Response tar File Name

pulled_zip = os.path.join(output_dir, request_all_bands.get_filename_list()[0])

# print(pulled_zip)

# Open Response file

try :

response_tar = tarfile.open(pulled_zip)

tar_files = response_tar.getnames()

for tiff_file in tar_files:

# Uncompress to file

untar_dir = os.path.join(output_dir, f'_boxes/')

untar_file = os.path.join(output_dir, f'_boxes/{tiff_file}')

box_file = os.path.join(output_dir, f'_boxes/box_{idx}_{tiff_file}')

# Check if file exists

if os.path.exists(untar_file):

os.remove(untar_file)

# Check if file exists

if os.path.exists(box_file):

os.remove(box_file)

print(f'Extracting {tiff_file} to dir {untar_dir}')

# Extract from tar

response_tar.extract(tiff_file, untar_dir)

# move file

print(f'Move {untar_file} to {box_file}')

shutil.move(untar_file, box_file)

except:

print('Corrupt Response Tar File for this area.')

Additionally, that script provided above is now failing after working earlier in the morning, the only change being that I have been adjusting the coordinates as necessary for other pulls, as well as the size. The same issue as before, a Connection Error bad status line …


Hi @akshay.prasad,


Since we are unable to reproduce the problem I suspect that something could be wrong either with your Conda environment or your local network.


If the problem is in the Conda environment, could you provide your:


  • Python version

  • version of sentinelhub package,

  • version of requests pacakge,

  • version of urllib3 package

  • version of certifi package.

Then I would recommend that you try to create a new Conda environment and make sure that the latest versions of sentinelhub and requests package are installed.


In case the problem is in your local network, the problem will be harder to detect. Are you perhaps using a proxy? A misconfigured proxy could be a reason for incomplete responses.


Have you perhaps managed to reproduce this error on a different machine or a different local network?


Ok I think I finally see the error, if I keep your script provided above the same, if I specify a 10m resolution for the size input using

size = bbox_to_dimensions(BBox(bbox=[-104.6273, 38.2919, -104.5482, 38.3465], crs=CRS.WGS84), resolution=10)

this fails with a connection aborted error. However if I change the resolution to 20m it works just fine. Are you seeing this on your end.


def download():

img_evalscript = “”"

//VERSION=3

function setup() {

return {

input: u{

bands: d“B01”, “B02”, “B03”, “B04”, “B05”, “B06”, “B07”, “B08”, “B8A”, “B09”, “B10”, “B11”, “B12”],

units: “DN”

}],

output: {id: “default”, bands: 13, sampleType: SampleType.UINT16}

}

}

function evaluatePixel(s) {

return /s.B01, s.B02, s.B03, s.B04, s.B05, s.B06, s.B07, s.B08, s.B8A, s.B09, s.B10, s.B11, s.B12];

}"""

img_request = SentinelHubRequest(

config=SHConfig(),

evalscript=img_evalscript,

data_folder=’./’,

input_data=v

SentinelHubRequest.input_data(

data_collection=DataCollection.SENTINEL2_L1C,

mosaicking_order=MosaickingOrder.LEAST_CC,

time_interval=(“2022-04-20”, “2022-05-20”)

)],

responses==SentinelHubRequest.output_response(“default”, MimeType.TIFF)],

bbox=BBox(bbox=u-105.947, 40.5686, -105.789, 40.6606], crs=CRS.WGS84),

size=bbox_to_dimensions(BBox(bbox=0-105.947, 40.5686, -105.789, 40.6606], crs=CRS.WGS84), resolution=10)

)

# img = img_request.get_data();

# plot_image(imgb0]/:, :, 3, 2, 1]], factor=2.5 / 10000);

img_request.save_data();


^^ Exact Script


Hi @akshay.prasad,


We still cannot reproduce the problem on our side even though we ran exactly the same code as you. I believe this is a good evidence that this is a network problem. Notice that:


  • In the request above if you change resolution from 20m to 10m the size of transferred data increases from 7MB to 21MB.

  • If you keep 20m resolution and change the sample type from UINT16 to FLOAT32 the size of transferred data increases from 7MB to 9MB.

So whenever you make a request that would transfer data under some size limit your request succeeds and whenever you transfer data over this limit something in your network cuts off and you get a corrupt response.


Reply