title: Connecting to a remote Cassandra Database through Python
body: <p>I need some help making a connection to a remote Cassandra database housed on an ec2 instance. Let's just dive right in. Here's my python script (I'm trying two different methods).</p>
  
  <pre><code>import cql
  from cassandra.cluster import Cluster
  
  cluster = Cluster(contact_points = ['172.XX.XX.XX',], port=&lt;port&gt;)
  session = cluster.connect('demo')
  
  while True:
      fname = raw_input('First name&gt; ')
      lname = raw_input('Last name&gt; ')
      session.execute("INSERT INTO demo (firstname, lastname) VALUES ('"+fname+"', '"+lname+"')")
  
  
  '''connection = cql.connect('172.XX.XX.XX', &lt;port&gt;, 'demo')
  print 'made connection'
  cur = connection.cursor()
  cur.execute("INSERT INTO example (firstname, lastname) VALUES ('Guy', 'Man');")
  '''
  </code></pre>
  
  <p>This is the error I keep getting.</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/user/Cassandra/remote connect.py", line 5, in &lt;module&gt;
  session = cluster.connect('demo')
  File "build/bdist.linux-x86_64/egg/cassandra/cluster.py", line 840, in connect
  self.control_connection.connect()
  File "build/bdist.linux-x86_64/egg/cassandra/cluster.py", line 2087, in connect
  self._set_new_connection(self._reconnect_internal())
  File "build/bdist.linux-x86_64/egg/cassandra/cluster.py", line 2122, in _reconnect_internal
  raise NoHostAvailable("Unable to connect to any servers", errors)
  NoHostAvailable: ('Unable to connect to any servers', {'172.XX.XX.XX': error(None, "Tried connecting to [('172.XX.XX.XX', &lt;port&gt;)]. Last error: None")})
  </code></pre>
  
  <p>This is how I configured cassandra.yaml</p>
  
  <pre><code>listen_address: 172.XX.XX.XX
  </code></pre>
  
  <p>It's set to the IP of the machine.</p>
  
  <pre><code>start_native_transport: true
  native_transport_port: 9042
  
  start_rpc: false
  
  rpc_address: 0.0.0.0
  
  broadcast_rpc_address: 172.XX.XX.XX
  </code></pre>
  
  <p>Set to the IP of the machine as well.</p>
  
  <p>Then I do <code>bin/cassandra -f</code> and get this error.</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to bind port 9042 on 0.0.0.0.
  </code></pre>
  
  <p>Then it announces shutdown.</p>
  
  <p>When I try <code>bin/cassandra</code> it says this-</p>
  
  <pre><code>INFO: No gossip backlog; proceeding
  </code></pre>
  
  <p>And then I've waited for 15 to 20 minutes to see if it does anything... it doesn't.</p>
  
  <p>Any help is appreciated! Thanks in advance!</p>