cassandra-python的使用方法就不介紹了
我的情況是在python3遠程連接cassandra時候報了這個錯
(如果你是python2項目完全可以用它自帶的cql,那個很穩定)
cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’,----------
試過很多方法都不好用,最後在Cluster的hosts列表裏多增加了相同的host就好用了。
猜測,cassandra-python 的集羣篩選有效host的效率不高,不能一次就中。所以多增加一些讓他重複幾次篩選就好了。
class *******:
.......
contact_points = [host]*20
auth_provider = PlainTextAuthProvider(username=user, password=passwd)
self.cluster = Cluster(contact_points,
auth_provider=auth_provider,
connect_timeout=100)
self.cursor = self.cluster.connect(database)