Skip to content

Instantly share code, notes, and snippets.

@dpwiz
Created January 31, 2012 12:00
Show Gist options
  • Save dpwiz/1710121 to your computer and use it in GitHub Desktop.
Save dpwiz/1710121 to your computer and use it in GitHub Desktop.
Using client certificate with requests library
# https://github.com/kennethreitz/requests/issues/30#issuecomment-3631717
def with_cert(session, key, cert=None):
"Monkeypatch session pool manager with client cert stuff"
session.poolmanager = session.poolmanager.__class__(
key_file = key,
cert_file = cert or key,
**session.poolmanager.connection_pool_kw)
return session
# usage:
from requests import Session
with_cert(Session(), 'my_cert.pem').get('https://193.201.228.75/', verify=False).content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment