';int';对象不可编辑:当我尝试使用Python在Cassandra中插入数据时

';int';对象不可编辑:当我尝试使用Python在Cassandra中插入数据时,python,cassandra,Python,Cassandra,在使用Python向Cassandra表插入数据时,我遇到了一些问题 代码: 错误: File "cassandra/cluster.py", line 2239, in cassandra.cluster.Session.execute File "cassandra/cluster.py", line 2279, in cassandra.cluster.Session.execute_async File "cassandra/cluster.py", line 2343, i

在使用Python向Cassandra表插入数据时,我遇到了一些问题

代码:

错误:

  File "cassandra/cluster.py", line 2239, in cassandra.cluster.Session.execute
  File "cassandra/cluster.py", line 2279, in cassandra.cluster.Session.execute_async
  File "cassandra/cluster.py", line 2343, in cassandra.cluster.Session._create_response_future
  File "cassandra/query.py", line 897, in genexpr
  File "cassandra/query.py", line 897, in genexpr
TypeError: 'int' object is not iterable

与python中的任何其他ORM一样,
.execute
的第二个参数在使用位置参数时必须是元组或列表:

session.execute(
    """
    insert into test.student(Student_id)
    values(%s)
    """,
    (56,))
#     ^ note the parenthesis and the REQUIRED trailing comma
#       to make this a single-element tuple
卡桑德拉的书中也提到了这一点:

注意:第二个参数必须始终使用序列,即使只传入一个变量

session.execute("INSERT INTO foo (bar) VALUES (%s)", "blah")  # wrong
session.execute("INSERT INTO foo (bar) VALUES (%s)", ("blah"))  # wrong
session.execute("INSERT INTO foo (bar) VALUES (%s)", ("blah", ))  # right
session.execute("INSERT INTO foo (bar) VALUES (%s)", ["blah"])  # right
session.execute("INSERT INTO foo (bar) VALUES (%s)", "blah")  # wrong
session.execute("INSERT INTO foo (bar) VALUES (%s)", ("blah"))  # wrong
session.execute("INSERT INTO foo (bar) VALUES (%s)", ("blah", ))  # right
session.execute("INSERT INTO foo (bar) VALUES (%s)", ["blah"])  # right