首页 > 解决方案 > 在我的 Ubuntu 服务器上使用 cURL、wget 和 Python 时出现 SSL 错误

问题描述

我在我的 Tinker Board 上运行了一个相当新的 Lubuntu 19.04 版本,从 ELAR Systems 下载。我想使用 Certbot 获得 SSL 证书,这是我得到 Python 错误的地方:

File "/tmp/tmp.7Ta16YELv4/pipstrap.py", line 177, in <module>
  sys.exit(main())
File "/tmp/tmp.7Ta16YELv4/pipstrap.py", line 158, in main
  for path, digest in PACKAGES]
File "/tmp/tmp.7Ta16YELv4/pipstrap.py", line 117, in hashed_download
  response = opener(using_https=parsed_url.scheme == 'https').open(url)
File "/usr/lib/python2.7/urllib2.py", line 429, in open
  response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 447, in _open
  '_open', req)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
  result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
  context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
  raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>

我希望这个错误与我在使用 wget 和 cURL 时遇到的 SSL 错误有关。

wget:

tinker@ELAR-Systems:~$ wget stackoverflow.com
--2019-12-29 22:33:53--  http://stackoverflow.com/
Resolving stackoverflow.com (stackoverflow.com)... 151.101.1.69, 151.101.65.69, 151.101.129.69, ...
Connecting to stackoverflow.com (stackoverflow.com)|151.101.1.69|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://stackoverflow.com/ [following]
--2019-12-29 22:33:54--  https://stackoverflow.com/
Connecting to stackoverflow.com (stackoverflow.com)|151.101.1.69|:443... connected.
ERROR: cannot verify stackoverflow.com's certificate, issued by ‘CN=Let's Encrypt Authority X3,O=Let's Encrypt,C=US’:
  Unable to locally verify the issuer's authority.
To connect to stackoverflow.com insecurely, use `--no-check-certificate'.

卷曲

tinker@ELAR-Systems:~$ curl -X GET -I https://pypi.python.org
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

我检查了/usr/share/ca-certificates空的文件夹,当我输入时sudo update-ca-certificates,它说0 added, 0 removed; done.。这有什么关系吗?

提前致谢!

标签: pythonpython-2.7ubuntusslssl-certificate

解决方案


使用以下代码段忽略 ssl 检查

导入 ssl
ssl._create_default_https_context = ssl._create_unverified_context


推荐阅读