Authority_cert_issuer和Authority_cert_serial_number都必须存在或都没有

时间:2019-04-02 16:59:40

标签: python ssl python-requests anaconda python-3.7

我在Anaconda 2018.12中使用Python 3.7.1并尝试通过具有自定义证书的公司网络内的请求进行get(),我使用了.pem作为证书,并且使用方式如下:

response = requests.get('https://www.google.com', verify='ssl/rootCA.pem')
print(response)

运行此命令时,出现以下错误:

File "run.py", line 29, in <module>
response = requests.get('https://www.google.com', verify='ssl/rootCA.pem')
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
conn.connect()
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 355, in connect
cert = self.sock.getpeercert()
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 360, in getpeercert
'subjectAltName': get_subj_alt_name(x509)
File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 210, in get_subj_alt_name
ext = cert.extensions.get_extension_for_class(
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\utils.py", line 162, in inner
result = func(instance)
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\x509.py", line 137, in extensions
self._backend, self._x509
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\decode_asn1.py", line 252, in parse
value = handler(backend, ext_data)
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\decode_asn1.py", line 376, in _decode_authority_key_identifier
key_identifier, authority_cert_issuer, authority_cert_serial_number
File "C:\ProgramData\Anaconda3\lib\site-packages\cryptography\x509\extensions.py", line 152, in __init__
"authority_cert_issuer and authority_cert_serial_number "

ValueError: authority_cert_issuer and authority_cert_serial_number must both be present or both None

我的证书很简单

-----BEGIN CERTIFICATE-----
... certificate in here ...
-----END CERTIFICATE-----

并且我以前曾经使用过具有相同证书(实际上是相同的.pem)的这种方法,所以我不确定导致该问题必须做些什么。

1 个答案:

答案 0 :(得分:0)

我通过放弃Anaconda来解决此问题,仅使用Python并使用以下命令设置了REQUESTS_CA_BUNDLE路径:

set REQUESTS_CA_BUNDLE=C:\Users\User\workspaces\ssl\rootCA.pem