Pycassa TypeError: str or unicode, unable to insert cassandra

My script is python and cassandra is a stax community data community.

TypeError: A str or unicode value was expected, but int was received instead (3902503)

this is the error i get when trying to insert into cassandra column family.

The code is as follows:

for x in feed:
    cf.insert(uuid.uuid4(), x)

x is a simple array of the form "{key: value}"

The error log suggests:

    Traceback (most recent call last):
      File "C:\Users\me\Desktop\pro1\src\pro1.py", line 73, in <module>
        str("swf"): str("aws")
      File "c:\Python27\lib\site-packages\pycassa\columnfamily.py", line 969, in insert
        mut_list = self._make_mutation_list(columns, timestamp, ttl)
      File "c:\Python27\lib\site-packages\pycassa\columnfamily.py", line 504, in _make_mutation_list
        columns.iteritems())
      File "c:\Python27\lib\site-packages\pycassa\columnfamily.py", line 503, in <lambda>
        return map(lambda (c, v): Mutation(self._make_cosc(_pack_name(c), _pack_value(v, c), timestamp, ttl)),
      File "c:\Python27\lib\site-packages\pycassa\columnfamily.py", line 462, in _pack_value
        return packer(value)
      File "c:\Python27\lib\site-packages\pycassa\marshal.py", line 231, in pack_bytes
        % (v.__class__.__name__, str(v)))
    TypeError: A str or unicode value was expected, but int was received instead (3902503)        

It seems that something is very small, I am missing here ... well, that's why I came here to ask experts!

+5
source share
1 answer

, . , BytesType, , pycassa . str dict ( python 2.7 ):

cf.insert(uuid.uuid4(), [{k: str(v) for k, v in d.iteritems()} for d in x])
+4

All Articles