datastax cassandra.cluster.NoHostAvailable

问题描述 投票:0回答:1

我完全按照 Datastax 网站所述部署 Datastax,甚至使用了 virtualenv,但随后出现错误:

cassandra.cluster.NoHostAvailable

我使用的是 Windows 10。

我听说当我的一个节点离线时可能会发生此错误,但我不知道这意味着什么或如何修复它。

当我尝试完全按照网站所述使用捆绑包和令牌部署 Datastax 时,我收到此错误:

raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'20ad12f9-ae53-4b0a-a66a-01fd426bbdd3-us-east1.db.astra.datastax.com:29042:3fc0355c-8dc0-4fde-b81f-b55692bc4856': RuntimeError("ssl_options specify 'check_hostname', but ssl.match_hostname is not provided. Patch or upgrade Python to use this option."), '20ad12f9-ae53-4b0a-a66a-01fd426bbdd3-us-east1.db.astra.datastax.com:29042:45c38e37-2440-46d5-9312-d7846a7df2a0': RuntimeError("ssl_options specify 'check_hostname', but ssl.match_hostname is not provided. Patch or upgrade Python to use this option."), '20ad12f9-ae53-4b0a-a66a-01fd426bbdd3-us-east1.db.astra.datastax.com:29042:ed8a594e-e434-435b-ba06-f8831de2d1fb': RuntimeError("ssl_options specify 'check_hostname', but ssl.match_hostname is not provided. Patch or upgrade Python to use this option.")})
python cassandra datastax
1个回答
0
投票

我听说当我的一个节点离线时可能会发生此错误,但我不知道这意味着什么或如何修复它。

如果您使用 Apache Cassandra®,情况确实如此。对于 Astra DB,我们介意您这样做,并且连接尝试不足以导致崩溃。

所以看起来您正在尝试从 Python 连接到 Astra DB。有一个文档介绍了如何以多种方式做到这一点。我将演示如何连接 Cassandra Python 驱动程序。

开始之前,请务必为

ASTRA_DB_TOKEN
ASTRA_DB_SECURE_BUNDLE_LOCATION
设置环境变量。在 Windows 中,这是通过命令行使用
set
命令完成的:

set ASTRA_DB_TOKEN=AstraCS:ASjPlHbTYourSecureTokenGoesHered3cdab53b
set ASTRA_DB_SECURE_BUNDLE_LOCATION=c:/yourbundlelocation/secure-connect-db.zip

对于代码,您首先需要从

Cluster
库中引入
PlainTextAuthProvider
cassandra
类:

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

username
设置为文字字符串“token”,然后从环境中引入
ASTRA_DB_TOKEN
ASTRA_DB_SECURE_BUNDLE_LOCATION

username = "token"
token = os.environ['ASTRA_DB_TOKEN']
secureBundleLocation = os.environ['ASTRA_DB_SECURE_BUNDLE_LOCATION']

接下来,我们将实例化

cloud_config
auth_provider
对象,如图所示。

cloud_config= {
        'secure_connect_bundle': secureBundleLocation,
        'use_default_tempdir': False,
}
auth_provider = PlainTextAuthProvider(username, token)

我们将使用这些对象来实例化

cluster
session
对象。

cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

现在我们的会话已连接(希望如此),您应该能够在

system.local
表上运行快速验证查询:

row = session.execute("select cluster_name from system.local").one()
if row:
    print("cluster name = " + row[0])
else:
    print("An error occurred.")

如果这对您不起作用,请编辑您的问题以包含任何相关代码和实际的错误消息。

© www.soinside.com 2019 - 2024. All rights reserved.