SSL:GAE / Go上的CERTIFICATE_VERIFY_FAILED

时间:2017-04-03 04:46:17

标签: google-app-engine go google-bigquery

我正在开发GAE / Go应用程序并尝试从本地开发服务器连接Google Big Query。

我的代码是这样的。

import (
  "cloud.google.com/go/bigquery"
  "golang.org/x/net/context"
  "google.golang.org/api/option"
  gaeLog "google.golang.org/appengine/log"
  newappengine "google.golang.org/appengine"
)

func MyFunc(c *gin.Context) {
  r := c.Request
  ctx := newappengine.NewContext(r)
  client, err := bigquery.NewClient(ctx, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH))
  if err != nil {
      (Error Handling)
  }

  tableList := client.Dataset(DATASET_ID).Tables(ctx)
  for {
    v, err := tableList.Next()
    if err == iterator.Done {
        break
    } else if err != nil {
        gaeLog.Errorf(ctx, "Failed to get meta-info: %v", err)
        return
    }
    :
  }
}

我使用goapp.bat serve命令调用了本地开发服务器。 当我发布请求时,我收到了错误。

api_dev.go:344: ERROR: Failed to get meta-info: Get https://www.googleapis.com/bigquery/v2/projects/myproject/datasets/mydataset/tables?alt=json&pageToken=: oauth2: cannot fetch token: Post https://accounts.google.com/o/oauth2/token: API error 6 (urlfetch: SSL_CERTIFICATE_ERROR): [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

我用google搜索“CERTIFICATE_VERIFY_FAILED”,但我能找到的只是python程序。我的申请是GAE / Go计划。

如何避免此错误?

1 个答案:

答案 0 :(得分:2)

这是因为Google更新了他们的服务器证书,但没有通知Go SDK团队,这仍然有旧的证书。

解决方案似乎相当简单。

  1. 转到google_appengine\lib\cacerts\
  2. cacerts.txt重命名为cacerts.txt.old,将urlfetch_cacerts.txt重命名为urlfetch_cacerts.txt.old
  3. 下载Python Linux SDK 1.9.52
  4. 在这个Python SDK中,还有google_appengine\lib\cacerts\目录和这两个证书文件。将它们复制到Go SDK。
  5. 飘柔!您现在拥有更新的证书。