Skip to content
Advertisement

Testing-containers and clickhouse-driver error:Unexpected EOF while reading bytes

I have these libraries installed:

testcontainers==2.5
clickhouse-driver==0.1.0

This code:

from testcontainers.core.generic import GenericContainer
from clickhouse_driver import Client


def test_docker_run_clickhouse():
    ch_container = GenericContainer("yandex/clickhouse-server")
    ch_container.with_bind_ports(9000, 9000)
    with ch_container as ch:

        client = Client(host='localhost')
        print(client.execute("SHOW TABLES"))


if __name__ == '__main__':
    test_docker_run_clickhouse()

I am trying to get a generic container with clickhouse DB running.

But it gives me: EOFError: Unexpected EOF while reading bytes.

I am using Python 3.5.2. How to fix this?

Advertisement

Answer

It takes some time to run a container. Add a time delay before executing operations.

import time
with ch_container as ch:
        time.sleep(3)
        client = Client(host='localhost')
        print(client.execute("SHOW TABLES"))
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement