我正在学习并设置我的cassandra集群并尝试使用python作为客户端与之交互.在yaml中,我将authenticator设置为PasswordAuthenticator.
所以现在我计划将我的用户名和密码提供给connect函数,但是找不到放置它们的位置.
cluster = Cluster(hosts)
session = cluster.connect(keyspace)
Run Code Online (Sandbox Code Playgroud)
基本上,您只提供主机和密钥空间.文档类型建议与匿名连接? http://datastax.github.io/python-driver/getting_started.html#connecting-to-cassandra
如果我只是使用该示例,我将收到以下错误
raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'hou722067': AuthenticationFailed('Remote end requires authentication.',)})
Run Code Online (Sandbox Code Playgroud)
是否通过一些配置文件提供了身份验证信息?它似乎是一个非常基本的功能,我无法想象它不在python客户端驱动程序中.我一定错过了什么.
简而言之,我的问题是:如何使用python登录cassandra?
提前感谢任何暗示!
=================================================得到了它想通了.
我应该在auth_provider字段中提供用户名和密码,该字段是一个函数,返回包含"username"和"password"键以及相应字符串值的字典.
像def getCredential(self,host)之类的东西:credential = {'username':'myUser','password':'myPassword'}返回凭证
cluster = Cluster(nodes,auth_provider = getCredential)