I'm having trouble connecting to Cassandra (running on an EC2 node) remotely (from my laptop). When I use the DataStax Python driver for Cassandra:
from cassandra.cluster import Cluster
cluster = Cluster(['10.X.X.X'], port=9042)
cluster.connect()
I get:
Traceback (most recent call last):
File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-23-dc85f20fd4f5>", line 1, in <module>
session = cluster.connect()
File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 755, in connect
self.control_connection.connect()
File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 1868, in connect
self._set_new_connection(self._reconnect_internal())
File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 1903, in _reconnect_internal
raise NoHostAvailable("Unable to connect to any servers", errors)
NoHostAvailable: ('Unable to connect to any servers', {'10.X.X.X': OperationTimedOut('errors=None, last_host=None',)})
But Cassandra is running because nodetool status
gives me:
UN 127.0.0.1 124.18 KB 256 100.0% 4d973e17-ae08-3aa1-81d2-605b92753694 rack1
Cassandra also seems to be listening on port 9042:
netstat -nltp | grep 9042
tcp6 0 0 0.0.0.0:9042 :::* LISTEN -
And I can telnet from my laptop to Cassandra:
$ telnet 10.X.X.X 9042
Trying 10.X.X.X...
Connected to ip-10-X-X-X.
Escape character is '^]'.
Relevant highlights from my cassandra.yaml:
start_native_transport: true
rpc_address: 0.0.0.0
rpc_port: 9160
broadcast_rpc_address: 10.X.X.X
/var/log/cassandra/system.log
shows nothing useful.
edit:
I can also connect to Cassandra using cqlsh 127.0.0.1 9042
on the server, and cqlsh 10.X.X.X 9042
from my laptop without any problems.
Solution
Looks like the one place where I tested my script (a Python console inside PyCharm) is, for some reason, the only place where my script does not work. No problems running as a script in PyCharm or in Python/iPython interactive mode. I will leave the question, as it contains a fairly complete checklist for Python-to-Cassandra connection troubleshooting.
UN 127.0.0.1 124.18 KB 256 100.0% 4d973e17-ae08-3aa1-81d2-605b92753694 rack1
– Def_Os