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

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

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

问题

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

  1. package main
  2. import "fmt"
  3. import "log"
  4. import "github.com/gocql/gocql"
  5. var (
  6. name, sex string
  7. age int
  8. )
  9. func main() {
  10. // 连接到集群
  11. cluster := gocql.NewCluster("127.0.0.1")
  12. cluster.Keyspace = "dbaccess"
  13. session, _ := cluster.CreateSession()
  14. defer session.Close()
  15. cluster.ProtoVersion = 4
  16. if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
  17. err != nil {
  18. log.Fatal(err)
  19. }
  20. fmt.Println(name, age)
  21. }

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

  1. cluster.ProtoVersion = 4

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

英文:

I get this error trying to compile:

  1. package main
  2. import "fmt"
  3. import "log"
  4. import "github.com/gocql/gocql"
  5. var (
  6. name, sex string
  7. age int
  8. )
  9. func main() {
  10. // connect to the cluster
  11. cluster := gocql.NewCluster("127.0.0.1")
  12. cluster.Keyspace = "dbaccess"
  13. session, _ := cluster.CreateSession()
  14. defer session.Close()
  15. cluster.ProtoVersion = 4
  16. if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
  17. err != nil {
  18. log.Fatal(err)
  19. }
  20. fmt.Println(name, age)
  21. }

I added the line

  1. 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,像这样:

  1. package main
  2. import "fmt"
  3. import "log"
  4. import "github.com/gocql/gocql"
  5. var (
  6. name, sex, age string
  7. )
  8. func main() {
  9. // 连接到集群
  10. cluster := gocql.NewCluster("127.0.0.1")
  11. cluster.ProtoVersion = 4
  12. cluster.Keyspace = "dbaccess"
  13. session, _ := cluster.CreateSession()
  14. defer session.Close()
  15. if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
  16. err != nil {
  17. log.Fatal(err)
  18. }
  19. fmt.Println(name, age)
  20. }

希望对其他人有所帮助 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:

  1. package main
  2. import &quot;fmt&quot;
  3. import &quot;log&quot;
  4. import &quot;github.com/gocql/gocql&quot;
  5. var (
  6. name, sex, age string
  7. )
  8. func main() {
  9. // connect to the cluster
  10. cluster := gocql.NewCluster(&quot;127.0.0.1&quot;)
  11. cluster.ProtoVersion = 4
  12. cluster.Keyspace = &quot;dbaccess&quot;
  13. session, _ := cluster.CreateSession()
  14. defer session.Close()
  15. if err := session.Query(&quot;SELECT name, age FROM people WHERE name=&#39;doug&#39;&quot;).Scan(&amp;name, &amp;age);
  16. err != nil {
  17. log.Fatal(err)
  18. }
  19. fmt.Println(name, age)
  20. }

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:

确定