batflaps
batflaps

Reputation: 271

golang gocql failed to connect to 127.0.0.1:9042 not enough bytes to read header require 9 got: 8

I get this error trying to compile:

package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
    name, sex string
    age int
)
func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("127.0.0.1")
    cluster.Keyspace = "dbaccess"
    session, _ := cluster.CreateSession()
    defer session.Close()
    cluster.ProtoVersion = 4
    if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age); 
    err != nil {
        log.Fatal(err)
    }
    fmt.Println(name, age)
}

I added the line

cluster.ProtoVersion = 4

After reading about it here but I'm too new to understand if that's my issue, or I did something wrong elsewhere. Do I have to wait for an update to gocql that fixes this, or what should I do?

Upvotes: 1

Views: 2356

Answers (1)

batflaps
batflaps

Reputation: 271

Okay, I sorted out with @Zariel on the github issue #538 thread. You have to put the ProtoVersion = 4 up by the first gocql stuff like:

package main
import "fmt"
import "log"
import "github.com/gocql/gocql"

var (
    name, sex, age string
)

func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("127.0.0.1")
    cluster.ProtoVersion = 4
    cluster.Keyspace = "dbaccess"
    session, _ := cluster.CreateSession()
    defer session.Close()

    if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age); 
    err != nil {
        log.Fatal(err)
    }
    fmt.Println(name, age)
}

Hope that helps someone else :)

Upvotes: 3

Related Questions