Python 卡桑德拉误差';非类型';对象没有属性';数据中心&x27;导入csv时

Python 卡桑德拉误差';非类型';对象没有属性';数据中心&x27;导入csv时,python,csv,cassandra,copy,nonetype,Python,Csv,Cassandra,Copy,Nonetype,我已经建立了一个带有3个节点的cassandra集群 我正在尝试使用copy命令执行简单的导出/导入,但失败,出现以下错误: cqlsh:walmart> select * from test; store | date | isholiday | dept -------+------------+-----------+------ 1 | 22/04/1993 | False | 1 cqlsh> use walmart; cqlsh

我已经建立了一个带有3个节点的cassandra集群

我正在尝试使用copy命令执行简单的导出/导入,但失败,出现以下错误:

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'
我研究了错误,每个相关链接似乎都指出了python的问题

我还安装了python驱动程序pip cassandra驱动程序。手动插入数据有效,但不能通过导出/导入

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

如何修复此错误

$CASSANDRA_HOME/logs
中的日志没有关于错误的任何条目

回溯:

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

问题在于您正在使用的cqlsh的构建,因为构建copyutil没有使用正确的主机进行连接。它已经出现在新版本中。只需克隆并运行
bin/cqlsh
,然后尝试相同的命令。

这不太好,但我将尝试解决这个问题。我是cassandra的新手,在尝试通过copy函数将数据导入cassandra表时遇到了完全相同的问题。我通过安装在虚拟机上的cqlsh连接到安装cassandra的服务器。因此,在运行cqlsh命令时,我必须指定服务器ip地址和端口:#cqlsh ip_address port 我像这样连接服务器名:#cqlsh myserver.example.com 9040,我连接了,但复制功能不起作用

但与服务器的数字ip地址连接(例如:

cqlsh 127.0.0.19040)它已经起作用了。 这纯粹是偶然的,我只是简单地测试了一下,它对我起了作用


如果有人能解释这一事实,那就太好了

非常感谢您分享解决方案。它的工作原理是在连接时指定ip和端口,就像您建议的那样。我以前确实指定了它,但是主机名而不是ip。同样的情况也适用于我。我是通过“localhost”而不是“127.0.0.1”连接的。解决方案:在连接时指定ip而不是主机名和端口:cassandra@cassandra-srv01:~$cqlsh 192.168.56.101 9042连接到fiap_集群,地址为192.168.56.101:9042。cqlsh>从“file.csv”复制walmart.test;使用1个子进程启动具有列[store、date、isholiday、dept]的walmart.test副本。已处理:1行;速率:2行/秒;平均速率:3行/s 1行在0.399秒内从1个文件导入(跳过0)。