Unable to open jp2 files from DownloadResponse objects

Hi, I’m downloading scene bands from Sentinel Hub using the get_data method of the AwsTileRequest class.
I’m passing “decode_data=False” as an argument to get_data, because I want the original jp2 files.
After the get_data method returns, I try opening the file using
rasterio.open(BytesIO(data.content)).
Unfortunately, I’m getting errors that seem to indicate the data is not in the expected format.

Here are the errors I’m getting:
ERROR 1: Expected a SOC marker
ERROR 1: opj_read_header() failed (psImage=0000000000000000)
ERROR 1: Marker is not compliant with its position
ERROR 1: Stream too short, expected SOT
ERROR 1: opj_get_decoded_tile() failed

The code I’m using looks like this:
list_of_data = req.get_data(decode_data=False)
data = list_of_data[0] # I confirmed that data is a DownloadResponse object
with rasterio.open(BytesIO(data.content)) as src:
values = src.read()

Can someone point me in the right direction?
Thanks in advance!

Hi, are a few helpful links:

  • this is how a DownloadResponse decodes itself (via method)
  • this is the module sentinelhub-py uses for decoding, to give you an idea on how we approach it

Thank you very much. These examples explain how to extract the numpy array, but not how to extract the jp2 file.
Do you know how the jp2 file can be extracted?