【发布时间】:2016-06-28 11:46:11
【问题描述】:
在我的 Cassandra 配置中,我启用了用户身份验证并通过 ssl 与 cqlsh 连接。 我在用 gocql 实现相同时遇到问题,以下是我的代码:
cluster := gocql.NewCluster("127.0.0.1")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "myuser",
Password: "mypassword",
}
cluster.SslOpts = &gocql.SslOptions {
CertPath: "/path/to/cert.pem",
}
当我尝试连接时出现以下错误:
gocql: unable to create session: connectionpool: unable to load X509 key pair: open : no such file or directory
在 python 中,我可以这样做:
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
USER = 'username'
PASS = 'password'
ssl_opts = {'ca_certs': '/path/to/cert.pem',
'ssl_version': PROTOCOL_TLSv1
}
credentials = PlainTextAuthProvider(username = USER, password = PASS)
# define host, port, cqlsh protocaol version
cluster = Cluster(contact_points= HOST, protocol_version= CQLSH_PROTOCOL_VERSION, auth_provider = credentials, port = CASSANDRA_PORT)
【问题讨论】: