Skip to content

Instantly share code, notes, and snippets.

@rectalogic
Created June 13, 2018 19:34
Show Gist options
  • Save rectalogic/30d62d2a13ecb76f65f2d4cc877d9af0 to your computer and use it in GitHub Desktop.
Save rectalogic/30d62d2a13ecb76f65f2d4cc877d9af0 to your computer and use it in GitHub Desktop.
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
# https://gist.github.com/mtigas/952344
# https://github.com/requests/requests/issues/2118
# https://github.com/requests/requests/issues/3774#issuecomment-267871876
class ClientCertificateAdapter(HTTPAdapter):
def init_poolmanager(self, *args, **kwargs):
context = create_urllib3_context()
context.load_cert_chain(certfile="client.crt", keyfile="client.key", password="cureatr")
kwargs['ssl_context'] = context
return super(ClientCertificateAdapter, self).init_poolmanager(*args, **kwargs)
s = requests.Session()
s.mount('https://server.cryptomix.com/secure/', ClientCertificateAdapter())
r = s.get('https://server.cryptomix.com/secure/')
print r.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment