Cassandra, pycassa "Insert argument" error

84 Views Asked by At
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'}})

the above code results in following error

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

What is the third argument which is needed to pass?

1

There are 1 best solutions below

0
Shoban Sundar On BEST ANSWER

The insert function in the column family takes following as arguments:

  1. row_key
  2. data

In your case I could see only the data is given.

Are you trying to insert {'customerID:'n2','Name':'n3'} as value for the row key 'n1' then change your syntax as:

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

Also see the pycassa documentation for your reference.

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