英文:
x509 certificate signed by unknown authority
问题
我正在尝试一些基本示例来请求网络数据,但是对不同主机的所有请求都会导致 SSL 错误:x509: certificate signed by unknown authority
。注意:我没有使用代理,也没有发生任何形式的证书拦截,因为使用 curl 或浏览器没有任何问题。
我目前正在使用的代码示例是:
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
response, err := http.Get("https://google.com")
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
}
编辑:代码在 Arch Linux 内核 4.9.37-1-lts 上运行。
编辑 2:显然 /etc/ssl/certs/ca-certificates.crt
在我的系统上与版本有差异,通过(重新)移除证书并手动重新安装 ca-certificates-utils
包,问题得到解决。
英文:
I'm trying some basic examples to request data from the web, however all requests to different hosts result in an SSL error: x509: certificate signed by unknown authority
. Note: I'm not behind a proxy and no forms of certificate interception is happening, as using curl or the browser works without problems.
The code sample I'm currently working with is:
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
response, err := http.Get("https://google.com")
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
}
Edit: Code is run on Arch linux kernel 4.9.37-1-lts.
Edit 2: Apparently /etc/ssl/certs/ca-certificates.crt
had a difference between the version on my system, by (re)moving the certificate and re-installing the ca-certificates-utils
package manually, the issue was solved.
答案1
得分: 9
根据你的错误信息,我猜测你正在使用Linux操作系统?
很可能你需要在运行程序的机器上安装ca-certificates。
在Ubuntu上,你可以执行以下命令:
sudo apt-get install ca-certificates
英文:
Based on your error, I'm assuming you are using Linux?
It's likely that you will have to install ca-certificates on the machine your program is running on.
On Ubuntu, you would execute something like this:
sudo apt-get install ca-certificates
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论