AntonioRB
AntonioRB

Reputation: 159

Effective way to connect Cassandra with Python (supress warnings)

I want to connect from a Cassandra Database using python driver.

I can connect using cassandra-driver, but i have several warning when i run the code in pycharm:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider


server_config = {
                "host": "172.XX.XX.XX",
                "port": "9042",
                "user": "XXXXXXXXX",
                "password": "XXXXXXXX",
                "keySpace": "XXXXXX"
    }


keyspace = server_config['keySpace']

auth_provider = PlainTextAuthProvider(username=server_config['user'],password=server_config['password'])

node_ips = [server_config['host']]



cluster = Cluster(contact_points=node_ips, load_balancing_policy=None, port=int(server_config['port']), auth_provider=auth_provider, protocol_version=3)

session = cluster.connect()

session.set_keyspace(keyspace)


But I have several warnings :

WARNING:cassandra.cluster:Cluster.__init__ called with contact_points specified, but no load_balancing_policy. In the next major version, this will raise an error; please specify a load-balancing policy. (contact_points = ['172.18.64.19'], lbp = None)

WARNING:cassandra.connection:An authentication challenge was not sent, this is suspicious because the driver expects authentication (configured authenticator = PlainTextAuthenticator)
INFO:cassandra.policies:Using datacenter 'datacenter1' for DCAwareRoundRobinPolicy (via host '172.18.64.19'); if incorrect, please specify a local_dc to the constructor, or limit contact points to local cluster nodes

WARNING:cassandra.connection:An authentication challenge was not sent, this is suspicious because the driver expects authentication (configured authenticator = PlainTextAuthenticator)

How can I connect more efficiently ?

Thanks !

Upvotes: 3

Views: 5290

Answers (1)

Alan Boudreault
Alan Boudreault

Reputation: 329

To avoid those warnings, you should follow their recommendations. Here are additional details about them:

  1. The first one recommend to specify a load balancing policy. In your code snippet, you configured it to None, which is the same than not configure it at all. Prefer configuring it explicitly based on your cluster configuration. Example:

# This example assume that *datacenter1* if a valid DC for your cluster.
Cluster(contact_points=node_ips, 
        load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='datacenter1'),
        port=int(server_config['port']), 
        auth_provider=auth_provider, 
        protocol_version=3)

  1. The second one is just saying that you should remove the auth_provider configuration because the cluster/node you are connecting to doesn't have authentication enabled.

Upvotes: 3

Related Questions