depicts/depicts/relaxed_ssl.py

26 lines
786 B
Python

"""Enable Python requests that ignores bad HTTPS certificates."""
import typing
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
CIPHERS = "DEFAULT@SECLEVEL=1"
class HTTPSAdapter(HTTPAdapter):
"""HTTPS Adapter subclass."""
def init_poolmanager(self, *args: typing.Any, **kwargs: typing.Any) -> None:
"""Init pool manager."""
context = create_urllib3_context(ciphers=CIPHERS)
kwargs["ssl_context"] = context
return super().init_poolmanager(*args, **kwargs) # type: ignore
def get(*args: typing.Any, **kwargs: typing.Any) -> requests.Response:
s = requests.Session()
s.mount("https://", HTTPSAdapter())
return s.get(*args, **kwargs, verify=False)