使用 Jupyter IPython 和 Cassandra 驱动程序
Using Jupyter IPython and Cassandra driver
我正在尝试将 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:
中执行代码时出现错误
WARNING:cassandra.cluster:Failed to create connection pool for new host 10.0.0.7
...
error: [Errno None] Tried connecting to [('10.0.0.7', 9042)]. Last error: None
WARNING:cassandra.pool:Error attempting to reconnect to 10.0.0.7, scheduling retry in 2.0 seconds: [Errno None] Tried connecting to [('10.0.0.7', 9042)]. Last error: None
(我正在使用 cassandra python 驱动程序 pip install cassandra-driver
)
会不会是 ip 地址或路由问题?针对“新主机”提到的错误消息指向本地 ip 地址,而不是我用来连接的地址。如果是这样的话,我想知道为什么 ipython 命令行与笔记本会产生不同的结果,所以它与笔记本处理连接的方式有关。有没有人知道为什么会出现这种情况以及我如何修复或解决此连接错误?
连接问题与使用内部 IP 地址通信的节点有关。遇到这个 post 这有助于澄清问题。
"When connecting to the cluster from external client using the the nodes' external IP addresses, these internal IPs gets returned as hosts, which makes the connection pool produce warnings since it can't connect to them."
仍然不确定为什么命令行和笔记本环境之间的行为不同,但我按照建议使用 WhiteListRoundRobinPolicy
解决了连接问题(在集群)
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()
我正在尝试将 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:
中执行代码时出现错误WARNING:cassandra.cluster:Failed to create connection pool for new host 10.0.0.7
...
error: [Errno None] Tried connecting to [('10.0.0.7', 9042)]. Last error: None
WARNING:cassandra.pool:Error attempting to reconnect to 10.0.0.7, scheduling retry in 2.0 seconds: [Errno None] Tried connecting to [('10.0.0.7', 9042)]. Last error: None
(我正在使用 cassandra python 驱动程序 pip install cassandra-driver
)
会不会是 ip 地址或路由问题?针对“新主机”提到的错误消息指向本地 ip 地址,而不是我用来连接的地址。如果是这样的话,我想知道为什么 ipython 命令行与笔记本会产生不同的结果,所以它与笔记本处理连接的方式有关。有没有人知道为什么会出现这种情况以及我如何修复或解决此连接错误?
连接问题与使用内部 IP 地址通信的节点有关。遇到这个 post 这有助于澄清问题。
"When connecting to the cluster from external client using the the nodes' external IP addresses, these internal IPs gets returned as hosts, which makes the connection pool produce warnings since it can't connect to them."
仍然不确定为什么命令行和笔记本环境之间的行为不同,但我按照建议使用 WhiteListRoundRobinPolicy
解决了连接问题(在集群)
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()