2015-08-26 109 views
1

我想用cassandra python驱动程序使用ipython笔记本。使用命令行ipython是完全正确的;我能够建立连接。但是,当我使用具有相同代码的Jupyter IPython笔记本时,遇到连接错误。使用Jupyter IPython和Cassandra驱动程序

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

我可以通过命令行使用ipython和python运行上面的3行。

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

(我用的卡珊德拉蟒蛇司机pip install cassandra-driver

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

回答

2

连接问题与节点与内部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的建议(显式指定集群中的公网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

相关问题