Bobbie
Bobbie

Reputation: 79

CQLSH COPY ERROR TypeError: 'int' object is not iterable

I have below code getting trying to dump table data but below error TypeError: 'int' object is not iterable.

import argparse
    import sys
    import itertools
    import codecs
    import uuid
    import os

    try:
        import cassandra
        import cassandra.concurrent
    except ImportError:
        sys.exit('Python Cassandra driver not installed. You might try \"pip install cassandra-driver\".')
    from cassandra.cluster import Cluster, ResultSet
    from cassandra.policies import DCAwareRoundRobinPolicy
    from cassandra.auth import PlainTextAuthProvider
    from cassandra.cluster import ConsistencyLevel

    datafile = "/Users/username/adf.csv"

    if os.path.exists(datafile):
        os.remove(datafile)
    def dumptableascsv():
        auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
        cluster = Cluster(['127.0.0.1'],
                          load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='Cassandra'),
                          port=9042, auth_provider=auth_provider)
        session = cluster.connect('qualys_ioc')
        session.execute("COPY qualys_ioc.agent_delta_fragment(agent_id , delta_id , fragment_id, boolean ,created_on)  TO "
                        "'/Users/username/adf.csv' WITH HEADER = true ;", ConsistencyLevel.QUORUM)
    dumptableascsv()

Upvotes: 1

Views: 275

Answers (1)

Adam Holmberg
Adam Holmberg

Reputation: 7375

COPY is a cqlsh commend -- it is not part of CQL, and cannot be executed via native protocol clients. You are getting this particular error instead of a server request error because you're passing a consistency level in the parameters position of Session.execute.

You can use cqlsh to do this from a script, or have a look at the DS Bulk tool for high performance loading and unloading.

Upvotes: 2

Related Questions