擅长:python、mysql、java
<p>您可以通过将丢失的中间证书添加到活动的<a href="https://pyopenssl.org/en/stable/api/crypto.html#x509store-objects" rel="nofollow noreferrer">X509Store</a>来解决此问题:</p>
<pre><code>cert_text = '''
-BEGIN CERTIFICATE -
...put your actual certificate text here...
-END CERTIFICATE -
'''
# fill this out depending on which specific intermediate cert you're missing
missing_cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert_text)
context = ssl.create_default_context() # load default trusted certificates
store = context.get_cert_store() # get the X509Store for that context
store.add_cert(missing_cert) # add your missing cert to it
urllib.request.urlopen(site, context=context)
</code></pre>
<p>请注意,如果您只需要与正在为其执行此操作的服务器通信,则可以将适当的<code>cafile</code>或{<cd2>}参数传递给<code>create_default_context()</code>。在</p>