gpt4 book ai didi

python - Alpine 3.3、Python 2.7.11、urllib2 导致 SSL : CERTIFICATE_VERIFY_FAILED

转载 作者:太空狗 更新时间:2023-10-29 18:03:42 26 4
gpt4 key购买 nike

我有这个小 Dockerfile

FROM alpine:3.3
RUN apk --update add python
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]

使用 docker build -t alpine-py/01 . 构建它,然后使用 docker run -it --rm alpine-py/01 运行它创建以下内容输出

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>

昨天我被最近发布的 OpenSSL 1.0.2g 咬伤了,导致 py-cryptograpy 无法编译。幸运的是,几个小时后,来自 py-cryptography 的人在 PyPI 上发布了一个新版本。问题是 OpenSSL 中的函数获得了新签名。

这可能是相关的还是我遗漏了什么?

最佳答案

您需要安装 ca-certificates 才能验证公共(public) CA 签名的证书:

FROM alpine:3.3
RUN apk --no-cache add python ca-certificates
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]

关于python - Alpine 3.3、Python 2.7.11、urllib2 导致 SSL : CERTIFICATE_VERIFY_FAILED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35762510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com