2015-08-26 104 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

相關問題