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

huangapple go评论73阅读模式
英文:

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

问题

我在尝试编译时遇到了这个错误:

package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
    name, sex string
    age int
)
func main() {
    // 连接到集群
    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)
}

我在阅读了这里的内容之后添加了这行代码:

cluster.ProtoVersion = 4

但是我还是太新了,不太明白这是否是我的问题,或者我在其他地方做错了什么。我是否需要等待一个修复此问题的 gocql 更新,或者我应该做些什么?

英文:

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 <a href="https://github.com/gocql/gocql/issues/538">here</a> 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?

答案1

得分: 3

好的,我为你翻译如下内容:

好的,我在github问题#538的讨论中与@Zariel解决了问题。你需要在第一个gocql的代码部分中添加ProtoVersion = 4,像这样:

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

var (
    name, sex, age string
)

func main() {
    // 连接到集群
    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)
}

希望对其他人有所帮助 golang gocql failed to connect to 127.0.0.1:9042 not enough bytes to read header require 9 got: 8

英文:

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 &quot;fmt&quot;
import &quot;log&quot;
import &quot;github.com/gocql/gocql&quot;

var (
    name, sex, age string
)

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

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

Hope that helps someone else golang gocql failed to connect to 127.0.0.1:9042 not enough bytes to read header require 9 got: 8

huangapple
  • 本文由 发表于 2016年1月18日 09:57:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/34846153.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定