Re: Is it possible to open a binary file with

Sean Gillies


If you pass a Python file object opened in "r" mode to, the contents will be read and stored in a MemoryFile. See Rasterio's open function doesn't accept bytes as an argument. Note that if the JP2 file is large, on the order of your computer's RAM, your program will be at risk of running out of memory.

On Sun, Apr 7, 2019 at 7:51 AM <htaidirt@...> wrote:
Hi all,

I've been using rasterio for few days, and now experiencing a situation where I can't find any help.

I read in the doc that when using `,...)` it is possible to pass a binary content as `fp` (doc in the source file ->

So instead of passing a file path or URL, I wanted to pass the content of the jp2 file to rasterio. Here is the full code for reproductability:

import boto3
import rasterio
s3 = boto3.resource('s3')

bucket = 'sentinel-s2-l1c'
key = 'tiles/31/U/DQ/2019/3/2/0/B01.jp2'

content = s3.Object(bucket, key).get(RequestPayer='requester')['Body'].read()
rio =, driver="JP2OpenJPEG").read(1)

But I'm getting an invalid path or file: b'\x00\x00\x00\x0cjP... error.

Any help on how to do so?


Sean Gillies

Join to automatically receive all group messages.