Python cassandra driver: error when trying to reconnect

I am using the python-cassandra driver and the cassandra cluster is on AWS. There are many warnings when connecting remotely. Does anyone have the same problem?

import of cassandra from cassandra.cluster import Cluster ... In [3]: cassandra. version From [3]: '2.5.1'

WARNING: cassandra.pool: error while reconnecting to 172.31.24.108, scheduling retry in 128.0 seconds: connection timed out to 172.31.24.108

+3


source to share


1 answer


I think this is because you cannot directly connect to 172.31.24.108 (private network?). in my situation, I can only connect to a subset of the cluster nodes. so what I do is follow the HostFilterPolicy doc and create my own filter.



    from cassandra.policies import HostFilterPolicy, RoundRobinPolicy

    CONN_HOSTS = ['172.235.33.32', '172.235.32.155']

    whitelist_filter_policy = HostFilterPolicy(
        child_policy=RoundRobinPolicy(),
        predicate=lambda host: host.address in CONN_HOSTS)
    # ...

    cluster = Cluster(
        contact_points=CONN_HOSTS,
        load_balancing_policy=whitelist_filter_policy,
        cql_version="3.2.1",
        protocol_version=3,
        ssl_options=ssl_options,
        port=9042,
        auth_provider=auth_provider)

      

0


source







All Articles