Cassandra、pycassa "Insert argument" 错误

Cassandra, pycassa "Insert argument" error

import pycassa
from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily

#creating a connection pool to cassandra keyspace(database)
pool = ConnectionPool('keyspace', ['100.66.185.96:9160'])

table = ColumnFamily(pool, "customers")

#opening the customer.csv file to parse in read mode
customerFile = open('customers.csv','r')

#Reading the file by ignoring the first line in the csv file 
records = customerFile.readlines()[:1]

#Parsing the records obtained by the csv file
for line in records:
  n1,n2,n2 = line.strip().split(";")
  #inserting records into table
  table.insert({"n1":{'customerID:'n2','Name':'n3'}})

以上代码导致以下错误

  table.insert()
  TypeError: insert() takes at least 3 arguments (2 given)

需要传递的第三个参数是什么?

列族中的insert函数接受以下参数:

  1. row_key
  2. 数据

在你的情况下,我只能看到给出的数据。

您是否尝试插入 {'customerID:'n2','Name':'n3'} 作为行键 'n1' 的值,然后将语法更改为:

table.insert('n1', {'customerID:'n2','Name':'n3'} )

另请参阅 pycassa 文档以供参考。

https://pycassa.readthedocs.io/en/latest/tutorial.html#inserting-data