背景
在linux 服務器上運行了一份python腳本,一直以來都是正常運行的。但是突然,天有不測風云,最近突然運行出錯了。查看出錯日志,發(fā)現(xiàn)如下錯誤信息。
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
看上去是腳本訪問某個 https 網(wǎng)頁失敗導致的。而且這個錯誤是偶現(xiàn)的,有時候,這個 https 網(wǎng)頁有時候又可以正常訪問。所以感覺這個問題特別的奇怪。
安裝 ssl 庫
其實以前有遇到這個問題,運行了以下倆條命令就解決了。命令如下:
yum install openssl-devel
yum install zlib-devel bzip2-devel sqlite sqlite-devel openssl-devel
執(zhí)行完這倆條命令,然而這次并不能順利解決問題。又出現(xiàn)了以下的錯誤信息。
curl https://www.baidu.com
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
簡單翻譯一下,就是百度的 ssl 證書不能被已知的 CA 驗證。所以用瀏覽器打開百度網(wǎng)站很正常,這樣看來應該是 linux 系統(tǒng)自帶的證書庫有點過時了吧,因此百度了一下,應該是需要更新證書庫。
更新證書庫
經(jīng)過一番Google, 發(fā)現(xiàn) linux 系統(tǒng)自帶的證書庫是 /etc/pki/tls/certs/ca-bundle.crt,所以大膽猜測是這個證書庫自身的問題,至于為什么時靈時不靈,還真沒有搞明白。時間比較緊急,先試一下更新一下本地證書庫吧。Linux命令如下:
安裝 ca-certificates
yum install ca-certificates
更新本地證書庫
update-ca-trust -h
usage: /usr/bin/update-ca-trust [extract | check | enable | disable | force-enable | force-disable ]
update-ca-trust check
PEM/JAVA Status: DISABLED.
(Legacy setup with static files.)
PKCS#11 module Status, see symbolic links reported below:
lrwxrwxrwx 1 root root 28 Jul 16 10:08 /etc/alternatives/libnssckbi.so.x86_64 -> /usr/lib64/nss/libnssckbi.so
(link resolving to NSS: using legacy static list)
(link resolving to p11-kit: using the new source configuration)
update-ca-trust enable
現(xiàn)在再試一下文章來源:http://www.zghlxwxcb.cn/news/detail-610804.html
curl https://www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head>......</html>
問題完美解決了。還有一個遺留的小問題是: linux 系統(tǒng)自帶的證書庫是 /etc/pki/tls/certs/ca-bundle.crt,但是時靈時不靈,這個問題還需要繼續(xù)研究。各位看官也歡迎一起探索。文章來源地址http://www.zghlxwxcb.cn/news/detail-610804.html
到了這里,關于解決linux 不能訪問 https 網(wǎng)站的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!