cassandra无主机可用:

2024-10-01 22:30:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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', {})

我对卡桑德拉有点陌生,如果有什么帮助的话,我会在我的大学委托书后面使用它。在

^{pr2}$

Tags: to代码inpyexecutesession错误line
1条回答
网友
1楼 · 发布于 2024-10-01 22:30:05

您似乎没有键空间: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)
)

相关问题 更多 >

    热门问题