Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

toni.rbaena_181533 avatar image
toni.rbaena_181533 asked ·

How do I avoid warnings connecting with the Python driver?

Hi all, 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)
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 !

python driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

aboudreault avatar image
aboudreault answered ·

Hi,


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)

2. 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.

1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks for your anwser, but i still have a warning message.

When i add


ALTER KEYSPACE XXXXX   WITH REPLICATION = {     'class' : 'NetworkTopologyStrategy',     'datacenter1' : 1    } ;


and use the code you wrote, I have this message :


DeprecationWarning: Legacy execution parameters will be removed in 4.0. Consider using execution profiles.  "execution profiles.", DeprecationWarning)
0 Likes 0 · ·