Python cassandra没有可用的主机:

Python cassandra没有可用的主机:,python,cassandra,Python,Cassandra,我尝试使用以下代码,但出现错误: 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) cassand

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

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', {})
我对卡桑德拉有点陌生,如果有什么帮助的话,我会在我的大学代理后面使用它

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

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

基于你的上述错误,我假设没有

CQL:


卡桑德拉在跑步吗?如果是这样,你确定它在那个端口上吗?如果Cassandra没有运行,他会收到:
NoHostAvailable:(“无法连接到任何服务器”,“127.0.0.1”:错误(61,“尝试连接到[('127.0.0.1',9042)]。
他的错误是因为没有键空间:demo。运行“cqlsh”是什么意思从最终结果到?
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)
)