【问题标题】:Using Jupyter IPython and Cassandra driver使用 Jupyter IPython 和 Cassandra 驱动程序
【发布时间】:2015-11-21 03:16:15
【问题描述】:

我正在尝试将 ipython notebook 与 cassandra python 驱动程序一起使用。使用命令行 ipython 完全没问题;我能够建立连接。但是,当我将 Jupyter IPython notebook 与相同的代码一起使用时,我遇到了连接错误。

from cassandra.cluster import Cluster
cluster = Cluster( contact_points=['xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx'] )
session = cluster.connect()

我可以通过命令行同时使用 ipython 和 python 运行上述 3 行。在 jupyter ipython notebook 中执行代码时出现错误:

警告:cassandra.cluster:无法为新主机 10.0.0.7 创建连接池

...

错误:[Errno None] 尝试连接到 [('10.0.0.7', 9042)]。最后一个错误:无

警告:cassandra.pool:尝试重新连接到 10.0.0.7 时出错,计划在 2.0 秒后重试:[Errno None] 尝试连接到 [('10.0.0.7', 9042)]。最后一个错误:无

(我使用的是cassandra python驱动pip install cassandra-driver

可能是 IP 地址或路由问题? “新主机”提到的错误消息指向本地 IP 地址,而不是我用来连接的地址。如果是这样的话,我想知道为什么 ipython 命令行与笔记本会产生不同的结果,所以它与笔记本如何处理连接有关。有没有人有任何见解为什么会出现这种情况,以及我可以如何修复或解决此连接错误?

【问题讨论】:

    标签: python cassandra ipython-notebook


    【解决方案1】:

    连接问题与与内部 IP 地址通信的节点有关。遇到了这个post,它有助于澄清问题。

    “当使用节点的外部 IP 地址从外部客户端连接到集群时,这些内部 IP 会作为主机返回,这会使连接池产生警告,因为它无法连接到它们。”

    仍然不确定为什么命令行和笔记本环境之间的行为不同,但我按照建议使用WhiteListRoundRobinPolicy 解决了连接问题(明确指定集群中的公共 IP 地址)

    from cassandra.cluster import Cluster
    from cassandra.policies import WhiteListRoundRobinPolicy
    
    lbp = WhiteListRoundRobinPolicy(['54.209.226.178', '52.7.220.112'])
    cluster = Cluster( contact_points=['54.209.226.178', '52.7.220.112'], load_balancing_policy=lbp )
    session = cluster.connect()
    

    更多关于WhiteListRoundRobinPolicy

    【讨论】:

      猜你喜欢
      • 2012-08-05
      • 2017-11-15
      • 2017-08-07
      • 2017-07-11
      • 2019-01-31
      • 1970-01-01
      • 2021-02-20
      • 2016-08-04
      • 2016-02-27
      相关资源
      最近更新 更多