0

I'm trying to connect Cassandra 2 database running protocol 2 from my python code:

def auth_provider(ip):
    return dict(username=cassandra_username,
                password=cassandra_password)

def cassandradb():
    cluster =  Cluster(cassandra_cluster,
                       load_balancing_policy=RoundRobinPolicy(),
                       port=cassandra_port,
                       auth_provider=auth_provider)
    session = cluster.connect(cassandra_keyspace)
    ...

The code raises an exception:

cassandra.cluster.NoHostAvailable: 
    ('Unable to connect to any servers', 
       {'127.0.0.1': UnsupportedOperation('Credentials-based authentication 
        is not supported with protocol version 2 or higher.  Use the SASL
        authentication mechanism instead.',)})

I have never worked with SASL. How should I change auth_provider or some other code place?

Maksym Polshcha
  • 18,030
  • 8
  • 52
  • 77

2 Answers2

0

https://datastax-oss.atlassian.net/browse/PYTHON-73

SASL based authentication is yet to be implemented in Python Driver 2.x. You can use 1.x driver version, which works fine with all recent cassandra versions.

Mikhail Stepura
  • 3,374
  • 20
  • 16
  • I know that, they created this ticket right after I submitted an issue into their github. Waiting for a patch. The thing is that I need v2 protocol due to its various benefits, v1 is useless for me. – Maksym Polshcha May 23 '14 at 05:05
0

The master branch of the driver was recently patched. Here is the working example:

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

auth_provider = PlainTextAuthProvider(username='cassandra', 
                                      password='cassandra')
cluster = Cluster(auth_provider=auth_provider)
Maksym Polshcha
  • 18,030
  • 8
  • 52
  • 77