title: java.io.IOException: Failed to open native connection to Cassandra at 127.0.0.1:9042
body: <p>I <a href="https://stackoverflow.com/q/30927615/4770813">found a similar post</a> but it didn't help.</p>
  
  <p>I've been working with Cassandra for a little while and now I'm trying to setup spark and spark-cassandra-connector. I'm using IntelliJ IDEA to do that (first time with IntelliJ IDEA and Scala too so, you get the picture)</p>
  
  <p>My OS is Windows 10. This is what I've done:</p>
  
  <p>Inside <strong>../spark-2.4.5-bin-hadoop2.7/bin</strong>: <code>spark-class.cmd org.apache.spark.deploy.master.Master</code></p>
  
  <p>Inside <strong>../spark-2.4.5-bin-hadoop2.7/bin</strong>: <code>spark-class.cmd org.apache.spark.deploy.worker.Worker -c 1 spark://192.168.0.3:7077</code></p>
  
  <p><strong>build.gradle</strong>  </p>
  
  <pre><code>apply plugin: 'scala'
  apply plugin: 'idea'
  apply plugin: 'eclipse'
  
  repositories {
      mavenCentral()
  }
  
  idea {
      project {
          jdkName = '1.8'
          languageLevel = '1.8'
      }
  }
  
  dependencies {
      compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.4.5'
      compile group: 'org.apache.spark', name: 'spark-sql_2.11', version: '2.4.5'
      compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.11'
      compile group: 'com.datastax.spark', name: 'spark-cassandra-connector_2.11', version: '2.4.0'
  }
  
  configurations.all {
      resolutionStrategy {
          force 'com.google.guava:guava:12.0.1'
      }
  }
  
  compileScala.targetCompatibility = "1.8"
  compileScala.sourceCompatibility = "1.8"
  </code></pre>
  
  <p><strong>SparkModule.scala</strong></p>
  
  <pre><code>package org.sentinel.spark_module
  
  import org.apache.spark.{SparkConf, SparkContext}
  import com.datastax.spark.connector._
  
  object SentinelSparkModule {
    def main(args: Array[String]) {
      val conf = new SparkConf().set("spark.cassandra.connection.host", "127.0.0.1")
        .set("spark.cassandra.connection.port", "9042")
        .setAppName("Sentinel").setMaster("spark://192.168.0.3:7077")
  
      val sc = new SparkContext(conf)
      val rdd = sc.cassandraTable("keyspace", "table")
      val values = rdd.groupBy((CassandraRow) =&gt; {
        @throws[Exception]
        def call(row: Nothing) = CassandraRow.getString("column")
      }).take(10).foreach(println)    
    }
  }
  </code></pre>
  
  <p>Even though the error occurs, I can still see the app running in <a href="http://localhost:8080/" rel="nofollow noreferrer">http://localhost:8080/</a> until I stop the execution in the IDE.
  <a href="https://i.stack.imgur.com/nBb4g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nBb4g.png" alt="enter image description here"></a></p>
  
  <p>Excerpt of the full stack dump:</p>
  
  <blockquote>
    <p><em>Exception in thread "main" java.io.IOException: Failed to open native</em>
    <em>connection to Cassandra at {127.0.0.1}:9042</em></p>
    
    <p><em>Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All</em>
    <em>host(s) tried for query failed (tried: /127.0.0.1:9042</em>
    <em>(com.datastax.driver.core.exceptions.OperationTimedOutException:</em>
    <em>[/127.0.0.1:9042] Operation timed out))</em></p>
  </blockquote>
  
  <p>Finally, even though it says it timed out, I am also querying Cassandra from my web app (node.js) as I'm coding this and the queries work fine. So, I don't know why it'd be a problem on Cassandra's part but, I guess it could be.</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>I included <code>compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '3.0.0'</code> and same error. (<a href="https://github.com/datastax/spark-cassandra-connector#version-compatibility" rel="nofollow noreferrer">version compatibility table</a>)</p>
  
  <p>EDIT:</p>
  
  <p><code>nodetool status</code> shows:</p>
  
  <pre><code>Datacenter: datacenter1
  ========================
  Status=Up/Down
  |/ State=Normal/Leaving/Joining/Moving
  --  Address    Load        Tokens       Owns (effective)  Host ID                               Rack
  UN  127.0.0.1  138.59 MiB  256          100.0%            77d808e6-5c57-494a-b6fb-7e73593dbb46  rack1
  </code></pre>
  
  <p>EDIT:</p>
  
  <p><code>cqlsh 127.0.0.1 9042</code> shows:</p>
  
  <pre><code>WARNING: console codepage must be set to cp65001 to support utf-8 encoding on Windows platforms.
  If you experience encoding problems, change your console codepage with 'chcp 65001' before starting cqlsh.
  
  Connected to Test Cluster at 127.0.0.1:9042.
  [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
  Use HELP for help.
  WARNING: pyreadline dependency missing.  Install to enable tab completion.
  cqlsh&gt;
  </code></pre>