To connect to a server using my local certificates I used to following setup:
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
zwep_session = None
class SSLContextAdapter(HTTPAdapter):
def init_poolmanager(self, *args, **kwargs):
context = create_urllib3_context()
kwargs['ssl_context'] = context
context.load_default_certs()
return super(SSLContextAdapter, self).init_poolmanager(*args, **kwargs)
def _zwep_session():
global zwep_session
if zwep_session is None:
zwep_session = requests.Session()
zwep_session.auth = (settings.ZWEP_USER, settings.ZWEP_PASSWORD)
zwep_session.mount(settings.ZWEP_SYSTEM_HOST, SSLContextAdapter())
return zwep_session
It worked, I don't see any changes in the repo, but now it suddenly doesn't work anymore:
AttributeError: 'PyOpenSSLContext' object has no attribute 'load_default_certs'enter code here
Currently it's running:
- requests: 2.22.0
- urlib3 1.25.10
The certificates in questions are internal certificates and therefore the local CA store should be used. The code should both run on windows local machines and ubuntu VPSs.
My question: Is this a good way to handle it? I don't completely understand what load_default_certs does, because I'm unable to locate the documentation & this fix is not my own creation.
Thanks for the help!