Open
Description
Hello,
I wish to use a custom adapter that I can use to access servers with old and expired certificates so I can automate the updating of the SSL certs. The doc isn't really clear, so I consider this a bug.
I have the following:
###########################################################################
class TruststoreAdapter(HTTPAdapter):
"""An adapter for requests. This supplies the a custom ssl_context to a set of requests."""
custom_context: truststore.SSLContext | ssl.SSLContext = None
def __init__(
self,
pool_connections=DEFAULT_POOLSIZE,
pool_maxsize=DEFAULT_POOLSIZE,
max_retries=DEFAULT_RETRIES,
pool_block=DEFAULT_POOLBLOCK,
ssl_context: truststore.SSLContext | ssl.SSLContext | None = None,
):
self.custom_context = ssl_context
super().__init__(
pool_connections=pool_connections,
pool_maxsize=pool_maxsize,
max_retries=max_retries,
pool_block=pool_block,
)
# ---------------------------------------------------------------------
def __str__(self) -> str:
return f"< {self.__class__.__name__} >"
# ---------------------------------------------------------------------
def __repr__(self) -> str:
return f"< {self.__class__.__name__} >"
# ---------------------------------------------------------------------
def init_poolmanager(self, connections, maxsize, block=False):
ctx = self.custom_context
return super().init_poolmanager(connections, maxsize, block, ssl_context=ctx)
Where the SSL Context is defined as:
ssl_context: truststore.SSLContext = truststore.SSLContext()
ssl_context.check_hostname = False
ssl_context.verify_mode = 0 # No check
Metadata
Assignees
Labels
No labels