我相信我正在按照文档中提到的方式进行操作Python-driver-AstraDB
cloud_config= {
'secure_connect_bundle': 'secure-connect-test-warehouse.zip'
}
logging.basicConfig(level=logging.DEBUG)
auth_provider = PlainTextAuthProvider(my_id, my_secret)
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()
row = session.execute("select release_version from system.local").one()
if row:
print(row[0])
else:
print("An error occurred.")
我收到以下错误:
File "connect_database.py", line 23, in <module>
session = cluster.connect()
File "cassandra/cluster.py", line 1677, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 1713, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 1700, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 3507, in cassandra.cluster.ControlConnection.connect
File "cassandra/cluster.py", line 3552, in cassandra.cluster.ControlConnection._reconnect_internal
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers
OSError(101, "Tried connecting to [('...', ..., 0, 0)]. Last error: Network is unreachable")})
我怀疑
Network is unreachable
与我尝试设置的网络延迟有关Cluster(cloud=cloud_config, auth_provider=auth_provider,control_connection_timeout=10)
control_connection_timeout的默认值为2.0,但我遇到了同样的问题。
如果正确我该如何解决这个问题?
文档说要使用安全连接捆绑包(SCB)的绝对路径,如下所示,
cloud_config= {
'secure_connect_bundle': '/path/to/secure-connect-database_name.zip'
}
注意: 设置集群初始化的 cloud_config 参数,如以下示例所示。 secure_connect_bundle 必须包含 Astra DB 数据库凭证的绝对路径 (secure-connect-database_name.zip)。
在这种情况下,您的代码应如下所示,
...
cloud_config= {
'secure_connect_bundle': '/your_path/to/secure-connect-test-warehouse.zip'
}
...
干杯!