Record.read_all() method throws ClientConnectionError

Hi, I get the following error from ReductStore Python SDK:

aiohttp.client_exceptions.ClientConnectionError: Connection closed

when running this code:

python 
async def get_images_from_records(records: List[Record]):
    images = []

    for record in records:
        dtype = record.labels.get("dtype")
        height = int(record.labels.get("height"))
        width = int(record.labels.get("width"))
        channels = int(record.labels.get("channels"))
        if "image" in str(record.labels.get("type")):
            image = np.frombuffer(await record.read_all(), dtype=dtype).reshape((height, width, channels))
            images.append(image)
        pass

    return images

any ways to fix this? for the same error in another function I used:

    async with Client("http://localhost:8383") as client:

but this cant be used here cause i dont need it

The aiohttp library downloads data via HTTP in two steps. First it downloads the HTTP headers, where we store all the metadata of records, then it downloads the body. The method record.read_all() tries to download body when the HTTP session is already closed. If you can’t work inside the context manager (async with client in Client(..)) you should download data where you receive the records.

1 Like