2016-03-02 51 views
0

我試圖將Python字典插入Cassandra。 但我在嘗試連接到數據庫時遇到了NoHostAvailable錯誤。 有人可以幫我搞清楚嗎?NoHostAvailable for Cassandra

代碼:

# cassandra server started in Terminal on Mac 
from cassandra.cluster import Cluster 
cluster = Cluster() 
session = cluster.connect() 

錯誤:

--------------------------------------------------------------------------- 
NoHostAvailable       Traceback (most recent call last) 
<ipython-input-21-dc85f20fd4f5> in <module>() 
----> 1 session = cluster.connect() 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.Cluster.connect (cassandra/cluster.c:11030)() 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.Cluster.connect (cassandra/cluster.c:10872)() 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.Cluster.connect (cassandra/cluster.c:10760)() 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.ControlConnection.connect (cassandra/cluster.c:35173)() 

/Users/a/anaconda/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:36007)() 

NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")}) 

警告:

WARNING:cassandra.cluster:[control connection] Error connecting to 127.0.0.1: 
Traceback (most recent call last): 
    File "cassandra/cluster.py", line 2067, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:35763) 
    return self._try_connect(host) 
    File "cassandra/cluster.py", line 2087, in cassandra.cluster.ControlConnection._try_connect (cassandra/cluster.c:36224) 
    connection = self._cluster.connection_factory(host.address, is_control_connection=True) 
    File "cassandra/cluster.py", line 789, in cassandra.cluster.Cluster.connection_factory (cassandra/cluster.c:8980) 
    return self.connection_class.factory(address, self.connect_timeout, *args, **kwargs) 
    File "cassandra/connection.py", line 306, in cassandra.connection.Connection.factory (cassandra/connection.c:5051) 
    conn = cls(host, *args, **kwargs) 
    File "/Users/a/anaconda/lib/python2.7/site-packages/cassandra/io/libevreactor.py", line 264, in __init__ 
    self._connect_socket() 
    File "cassandra/connection.py", line 340, in cassandra.connection.Connection._connect_socket (cassandra/connection.c:6123) 
    raise socket.error(sockerr.errno, "Tried connecting to %s. Last error: %s" % ([a[4] for a in addresses], sockerr.strerror or sockerr)) 
error: [Errno 61] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused 
ERROR:cassandra.cluster:Control connection failed to connect, shutting down Cluster: 
Traceback (most recent call last): 
    File "cassandra/cluster.py", line 844, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:10760) 
    self.control_connection.connect() 
    File "cassandra/cluster.py", line 2041, in cassandra.cluster.ControlConnection.connect (cassandra/cluster.c:35173) 
    self._set_new_connection(self._reconnect_internal()) 
    File "cassandra/cluster.py", line 2076, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:36007) 
    raise NoHostAvailable("Unable to connect to any servers", errors) 
NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")}) 
+2

最明顯的答案是您的本地系統沒有運行cassandra,或者它沒有在127.0.0.1:9042上進行監聽。 卡桑德拉正在運行?它在9042上收聽嗎?你可以用telnet連接嗎? –

回答

0

連接到羣集之前,你必須提供節點接觸點,並權威性提供商或者你有在本地主機IP地址上運行cassandra。

嘗試:

ap = PlainTextAuthProvider(username=<username>,password=<password>) 
cass_contact_points=[<ip address of your node>,..] 
cluster = Cluster(cass_contact_points,auth_provider=ap) 
session = cluster.connect(<keyspace name>) 
相關問題