如何传递用户名和密码到cassandra在python [英] How to pass along username and password to cassandra in python
问题描述
我正在学习,只是设置我的cassandra集群,并试图使用python作为客户端与它进行交互。在yaml中,我将验证器设置为PasswordAuthenticator。
现在我打算提供我的用户名和密码给connect函数,但没有找到它们放在哪里。
cluster = Cluster(hosts)
session = cluster.connect(keyspace)
基本上,您只提供主机和键空间。文档类型建议与匿名的连接?
http://datastax.github.io/python-driver/getting_started。 html#connecting-to-cassandra
如果我只是使用示例,我会收到以下错误
raise NoHostAvailable(无法连接到任何服务器,错误)
cassandra.cluster.NoHostAvailable:('无法连接到任何服务器',{'hou722067 ':AuthenticationFailed('Remote end requires authentication。',}}
一些配置文件?它似乎是一个非常基本的功能,我不能想象它没有涵盖在python客户端驱动程序。
总之,我的问题是:如何使用python登录cassandra?
提前感谢任何提示!
========================== ======================
有了它。
我应该提供auth_provider字段中的用户名和密码,该字段返回包含具有适当字符串值的username和password键的字典。
类似
def getCredential(self,host):
credential = {'username':'myUser','password':'myPassword'}
返回凭证
cluster = Cluster(nodes,auth_provider = getCredential)
按照ops建议使用:
从cassandra.cluster导入集群
def getCredential(self):
return {'username':'foo' ,'password':'bar'}
node_ips = ['0.0.0.0','0.0.0.1']
cluster = Cluster(node_ips,protocol_version = 1, auth_provider = getCredential)
session = cluster.connect()
版本2,那么您必须使用AuthProvider对象进行身份验证。 EX:
从cassandra.auth导入PlainTextAuthProvider
pre>
从cassandra.cluster导入集群
ap = PlainTextAuthProvider(username = foo,password = bar)
c = Cluster(protocol_version = 2,auth_provider = ap)
s = c.connect()
有人可以使用这些方法中的任何一种解释最佳做法,以便使用远程群集进行身份验证?
I'm learning and just setup my cassandra cluster and trying to use python as the client to interact with it. In the yaml, I set the authenticator to be PasswordAuthenticator.
So now I plan to provide my username and password over to the connect function but find no where to put them.
cluster = Cluster(hosts) session = cluster.connect(keyspace)
Basically, you provide only the host and the keyspace. The documentation kind of suggest a connection with anonymous? http://datastax.github.io/python-driver/getting_started.html#connecting-to-cassandra
If I just use the example, I will get the following error
raise NoHostAvailable("Unable to connect to any servers", errors) cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'hou722067': AuthenticationFailed('Remote end requires authentication.',)})
Is the authentication information supplied through some config files? It seems like a very basic functionality and I can't imagine it's not covered in the python client driver. I must have miss something.
In short, my question is: How do I login to cassandra using python?
Thanks in advance for any hint possible!
================================================= Got it figured.
I should provide the username and password in the auth_provider field which is a function returning a dictionary containing ‘username’ and ‘password’ keys with appropriate string values.
Something like def getCredential(self, host): credential = {'username':'myUser', 'password':'myPassword'} return credential
cluster = Cluster(nodes, auth_provider=getCredential)
解决方案Following the ops recommendation use:
from cassandra.cluster import Cluster def getCredential(self): return {'username': 'foo', 'password': 'bar'} node_ips = ['0.0.0.0', '0.0.0.1'] cluster = Cluster(node_ips, protocol_version=1, auth_provider=getCredential) session = cluster.connect()
If you're using protocol version 2 then you must authenticate with an AuthProvider object. EX:
from cassandra.auth import PlainTextAuthProvider from cassandra.cluster import Cluster ap = PlainTextAuthProvider(username=foo, password=bar) c = Cluster(protocol_version=2, auth_provider=ap) s = c.connect()
Can someone can explain best practices using either of these methods to authenticate with a remote cluster?
这篇关于如何传递用户名和密码到cassandra在python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!