gpt4 book ai didi

python - cassandra 没有主机可用 :

转载 作者:行者123 更新时间:2023-12-04 12:50:43 25 4
gpt4 key购买 nike

我尝试使用以下代码,但出现错误:

File "cassandra/cluster.py", line 1961, 
in cassandra.cluster.Session.execute (cassandra/cluster.c:34076)
File "cassandra/cluster.py", line 3649,
in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:69755)
cassandra.cluster.NoHostAvailable:
('Unable to complete the operation against any hosts', {})

我对 cassandra 有点陌生,如果有任何帮助,我会在我的大学代理后面使用它。

from cassandra.cluster import Cluster
cluster=Cluster(['127.0.0.1'],port=9042)
session=cluster.connect('demo')
session.execute(
"""
INSERT INTO users (name, credits)
VALUES (%s, %s)
""",
("John O'Reilly", 42)
)

最佳答案

看来你没有键空间:demo

如果您引用的示例与 DataStax Documentation 上的示例相似页面,您是否已经创建了 demo 键空间和用户表?

根据您的上述错误,我假设不是。

CQL:

from cassandra.cluster import Cluster


cluster = Cluster(['127.0.0.1'], port=9042)
session = cluster.connect() # Don't specify a keyspace here, since we haven't created it yet.

# Create the demo keyspace
session.execute(
"""
CREATE KEYSPACE IF NOT EXISTS demo WITH REPLICATION = {
'class' : 'SimpleStrategy',
'replication_factor' : 1
}
"""
)

# Set the active keyspace to demo
# Equivalent to: session.execute("""USE demo""")
session.set_keyspace('demo')

# Create the users table
# This creates a users table with columns: name (text) and credits (int)
session.execute(
"""
CREATE TABLE users (
name text PRIMARY KEY,
credits int
);
"""
)

# Execute your original insert
session.execute(
"""
INSERT INTO users (name, credits)
VALUES (%s, %s)
""",
("John O'Reilly", 42)
)

关于python - cassandra 没有主机可用 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39135096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com