我正在尝试使用urlopen连接到内部网站。而且无论是否提供cafile,它都会反复出现SSL错误。在
我尝试了stackoverflow答案中解释的各种方法。但运气不好。在urllib2.urlopen(url,cafile=certifi.where())
第二种方法:
^{pr2}$
第三种方式:ctx = ssl.create_default_context()
ctx.load_verify_locations(cafile = certifi.where())
urllib2.urlopen(url,context=ctx)
不管怎样,我尝试,我得到以下错误。在Traceback (most recent call last):
File "", line 1, in
File "urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "urllib2.py", line 429, in open
response = self._open(req, data)
File "urllib2.py", line 447, in _open
'_open', req)
File "urllib2.py", line 407, in _call_chain
result = func(*args)
File "urllib2.py", line 1241, in https_open
context=self._context)
File "urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError:
我已将CA证书的条目添加到文件中认证地点()也是。我使用python版本2.7.14。在
有人能告诉我我是不是错过了什么?或者我使用的python版本不支持它?另外,让我知道调试的方法,也就是找出CA证书是否有任何问题。在
谢谢。在
编辑:我不想按照urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error中的一个答案中的建议,选择退出SSL验证。另一个答案告诉我在urlopen中使用cafile,这在我的例子中不起作用。我试过这个问题的答案中给出的解决办法,但运气不好。在
另外,openssl抛出以下错误。在[root@host1 ~]# openssl s_client -connect url -CAfile "cacert.pem"
...
Certificate chain
...
Server certificate
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
...
No client certificate CA names sent
...
SSL handshake has read 2098 bytes and written 415 bytes
...
Verify return code: 2 (unable to get issuer certificate)
---
HTTP/1.0 408 Request Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html
408 Request Time-out
Your browser didn't send a complete request in time.
closed