2

I am trying to connect to cluster nodes having different ports (9042 and 9043), but cannot find ways to do it here:

cluster = Cluster(['0.0.0.0','0.0.0.0'],port=9042)

How do I do it?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Volatil3
  • 14,253
  • 38
  • 134
  • 263

1 Answers1

0

As of v3.27 of the DataStax's Python driver for Cassandra, Cluster's contact_points parameter seems to accept a tuple of IP and port.

https://github.com/datastax/python-driver/blob/3.27.0/cassandra/cluster.py#L581-L585

class Cluster(object):
    ...

    contact_points = ['127.0.0.1']
    """
    The list of contact points to try connecting for cluster discovery. A
    contact point can be a string (ip or hostname), a tuple (ip/hostname, port) or a
    :class:`.connection.EndPoint` instance. 

You can do

cluster = Cluster(
    contact_points=[
      ('0.0.0.0', 9042),
      ('0.0.0.0', 9043),
    ]
    ...
)

and then just leave the port= parameter as empty.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135