Last active
October 24, 2024 07:52
-
-
Save zeehio/7a5f780462f49c29a1cc96c429425da1 to your computer and use it in GitHub Desktop.
Use requests with truststore from a package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use requests with truststore from a package | |
# | |
# from requests_truststore import requests | |
# resp = requests.get("https://google.com") | |
from requests import Session | |
from requests.adapters import HTTPAdapter | |
import ssl | |
import truststore | |
class TrustStoreHTTPAdapter(HTTPAdapter): | |
def init_poolmanager(self, *args, **kwargs): | |
context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) | |
super().init_poolmanager(*args, **kwargs, ssl_context=context) | |
def _get_request_session(): | |
client_session = Session() | |
client_session.mount("https://", TrustStoreHTTPAdapter()) | |
return client_session | |
requests = _get_request_session() | |
__all__ = ['requests', 'TrustStoreHTTPAdapter'] | |
if __name__ == '__main__': | |
resp = requests.get("https://google.com") | |
print(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment