英文:
SSL: CERTIFICATE_VERIFY_FAILED on GAE/Go
问题
我正在开发 GAE/Go 应用程序,并尝试从本地开发服务器连接 Google BigQuery。
我的代码如下所示。
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 {
(错误处理)
}
tableList := client.Dataset(DATASET_ID).Tables(ctx)
for {
v, err := tableList.Next()
if err == iterator.Done {
break
} else if err != nil {
gaeLog.Errorf(ctx, "获取元信息失败:%v", err)
return
}
// 其他操作
}
}
我使用 goapp.bat serve
命令启动了本地开发服务器。当我发送请求时,出现了错误。
api_dev.go:344: 错误:获取元信息失败:Get https://www.googleapis.com/bigquery/v2/projects/myproject/datasets/mydataset/tables?alt=json&pageToken=: oauth2: 无法获取令牌:Post https://accounts.google.com/o/oauth2/token: API 错误 6 (urlfetch: SSL_CERTIFICATE_ERROR): [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
我搜索了 "CERTIFICATE_VERIFY_FAILED",但我找到的都是 Python 程序。我的应用程序是 GAE/Go 程序。
我该如何避免这个错误?
英文:
I am developing GAE/Go application and trying to connect Google Big Query from local development server.
My code is like this.
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
}
:
}
}
I invoked local development server with goapp.bat serve
command.
When I posted a request, I got an error.
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)
I googled "CERTIFICATE_VERIFY_FAILED", but all I can find is python program. My application is GAE/Go program.
How can I avoid this error?
答案1
得分: 2
这是因为Google已经更新了他们的服务器证书,但是他们没有通知Go SDK团队,所以Go SDK仍然使用旧的证书。
解决方案似乎相当简单。
- 进入
google_appengine\lib\cacerts\
目录。 - 将
cacerts.txt
重命名为cacerts.txt.old
,将urlfetch_cacerts.txt
重命名为urlfetch_cacerts.txt.old
。 - 下载Python Linux SDK 1.9.52。
- 在这个Python SDK中,也有一个
google_appengine\lib\cacerts\
目录,里面有这两个证书文件。将它们复制到你的Go SDK中。 - 庆祝吧!你现在拥有更新的证书。
英文:
This is because Google has updated their server certificates but have not notified the Go SDK team of this, which still has the old certs.
The solution seems fairly simple.
- Go to
google_appengine\lib\cacerts\
- Rename
cacerts.txt
tocacerts.txt.old
, andurlfetch_cacerts.txt
tourlfetch_cacerts.txt.old
- Download the Python Linux SDK 1.9.52.
- In this Python SDK there's also
google_appengine\lib\cacerts\
directory with those two cert files. Copy them over to your Go SDK. - Rejoice! You now have newer certs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论