python - 导入 csv 时 Cassandra 错误 'NoneType' 对象没有属性 'datacenter'

标签 python csv cassandra copy nonetype

我已经设置了一个包含 3 个节点的 cassandra 集群。

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

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-driver。手动插入数据有效,但不能通过导出/导入。

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

最佳答案

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

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

cqlsh 127.0.0.1 9040) 成功了。

纯属偶然,我只是简单地测试了一下,它对我有用。

如果这里有人可以解释这个事实,那就太好了!

关于python - 导入 csv 时 Cassandra 错误 'NoneType' 对象没有属性 'datacenter',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39308666/

相关文章:

python - 输出为 html 时如何增加 jupyter 笔记本/实验室单元宽度

python - 使用 Python 更新 csv 文件中的现有列和行

python 导入 csv 列表

database - 如何为 Cassandra 中的列添加 NOT NULL 约束?

python - 无法使用 DataStax Python 驱动程序远程连接到 Cassandra

python - django 模板问题(访问列表)

python - 使用 python 打印 bash 历史记录

python - 绘制长度不均匀的分布

c++ - 使用基本构造函数创建派生对象

cassandra - 如何在cassandra中使用cql查询获取系统日期