Skip to main content

Add PKCS#12 support to the requests library in a clean way, without monkey patching or temporary files

Project description

This library adds PKCS#12 support to the Python requests library.

It is a clean implementation: it uses neither monkey patching nor temporary files. Instead, it is integrated into requests as recommended by its authors: creating a custom TransportAdapter, which provides a custom SSLContext.

This library is meant to be a transitional solution until this functionality is provided by requests directly. However, that will take some time. See the corresponding issue for more details.

Usage

For simple one-off requests you can use this library as a drop-in replacement for the requests library:

from requests_pkcs12 import get

r = get('https://example.com/test', pkcs12_filename='clientcert.p12', pkcs12_password='correcthorsebatterystaple')

If you are using requests sessions, use the Pkcs12Adapter:

from requests import Session
from requests_pkcs12 import Pkcs12Adapter

with Session() as s:
    s.mount('https://example.com', Pkcs12Adapter(pkcs12_filename='clientcert.p12', pkcs12_password='correcthorsebatterystaple'))
    r = s.get('https://example.com/test')

Installation

This library is available as PyPI package:

pip install requests-pkcs12

Alternatively, you can retrieve the latest development version via Git:

git clone https://github.com/m-click/requests_pkcs12

Arguments

The following keyword arguments are supported:

  • pkcs12_filename is a byte string or unicode string that contains the file name of the encrypted PKCS#12 certificate.

    • Either this argument or pkcs12_data must be provided.

  • pkcs12_data is a byte string that contains the encrypted PKCS#12 certificate data.

    • Either this argument or pkcs12_filename must be provided.

  • pkcs12_password is a byte string or unicode string that contains the password.

    • This argument must be provided whenever pkcs12_filename or pkcs12_data is provided.

  • ssl_protocol is a protocol version from the ssl library.

    • This argument is optional and defaults to ssl.PROTOCOL_TLS.

If you use these parameters, don’t use the built-in cert parameter of requests at the same time. However, do use the other parameters. In particular, do use the “verify” parameter to verify the server-side certificate.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_pkcs12-1.10.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_pkcs12-1.10-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file requests_pkcs12-1.10.tar.gz.

File metadata

  • Download URL: requests_pkcs12-1.10.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for requests_pkcs12-1.10.tar.gz
Algorithm Hash digest
SHA256 bff6b6ae27c6c100e2d1f767a5db836692b3756564ca28fa718fea226fd4204c
MD5 2a93891027e4bbdf8438d8eeaf26b18d
BLAKE2b-256 5865f0f2045f57c37d43666288a92be44bfaeae4951424c8eb552e726a1ab97a

See more details on using hashes here.

File details

Details for the file requests_pkcs12-1.10-py2.py3-none-any.whl.

File metadata

  • Download URL: requests_pkcs12-1.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for requests_pkcs12-1.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21ef003813fa9224d132c98b531ff4eb05a81de410618cc4b84493ba22bf5a1b
MD5 82a7178c4f03ee664614e94c0bf33461
BLAKE2b-256 a7ca2fe9627effd527ae32c5cce48726e07a55cdba6a22d55a80bf56fe3931e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page