Search code examples
pythoncsvcassandracopynonetype

Cassandra error 'NoneType' object has no attribute 'datacenter' while importing csv


I have set up a cassandra cluster with 3 nodes.

I am trying to do a simple export/ import using copy command, but it fails with the following error:

cqlsh:walmart> select * from test;

 store | date       | isholiday | dept
-------+------------+-----------+------
     1 | 22/04/1993 |     False |    1


cqlsh> use walmart;
cqlsh:walmart> copy test to 'test.csv';
'NoneType' object has no attribute 'datacenter'

I researched the error and every related link seems to point out to python problems.

I also installed python driver pip cassandra-driver. Inserting data manually works, but not through export/ import.

cassandra@cassandra-srv01:~$ python -c 'import cassandra; print cassandra.__version__'
3.6.0

Ubuntu 16.04 64bit.

how can I fix this error?

the logs inside $CASSANDRA_HOME/logs don't have any entries regarding the error.

Traceback:

Traceback (most recent call last):
  File "/usr/local/Cellar/cassandra/3.7/libexec/bin/cqlsh.py", line 1152, in onecmd
    self.handle_statement(st, statementtext)
  File "/usr/local/Cellar/cassandra/3.7/libexec/bin/cqlsh.py", line 1189, in handle_statement
    return custom_handler(parsed)
  File "/usr/local/Cellar/cassandra/3.7/libexec/bin/cqlsh.py", line 1907, in do_copy
    task = ImportTask(self, ks, table, columns, fname, opts, DEFAULT_PROTOCOL_VERSION, CONFIG_FILE)
  File "/usr/local/Cellar/cassandra/3.7/libexec/bin/../pylib/cqlshlib/copyutil.py", line 1061, in __init__
    CopyTask.__init__(self, shell, ks, table, columns, fname, opts, protocol_version, config_file, 'from')
  File "/usr/local/Cellar/cassandra/3.7/libexec/bin/../pylib/cqlshlib/copyutil.py", line 207, in __init__
    self.local_dc = shell.conn.metadata.get_host(shell.hostname).datacenter
AttributeError: 'NoneType' object has no attribute 'datacenter

Solution

  • it is not so good, but i will try to contribute to the problem. i'm new in cassandra and had exactly the same problem while trying to import data into a cassandra table via the copy function. i connect to the server on which cassandra is installed through cqlsh installed on a virtual machine. so i have to specify the server ip address and the port while running the cqlsh command: # cqlsh ip_address port i connected with the servername like that: # cqlsh myserver.example.com 9040 and i was connected and the copy fonction didn't work.

    But connecting with the numerical ip address of the server (for example:

    cqlsh 127.0.0.1 9040) it has worked.

    it was by pure chance, i have simply tested and it has worked for me.

    when someone here can explain this fact it would be great!