Python Certifi Win32

1.6.1 · maintenance · verified Mon Apr 13

python-certifi-win32 is a Python package that patches the `certifi` module at runtime to include certificates from the Windows certificate store. This allows applications like `requests` (and tools based on it, such as `pip`) to verify TLS/SSL connections to servers whose Certificate Authorities (CAs) are trusted by the Windows operating system. The package is currently at version 1.6.1, but is generally unmaintained and has been superseded by `pip-system-certs`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how `python-certifi-win32` is intended to work. After installation, it transparently patches `certifi` to include Windows system certificates. When libraries like `requests` make HTTPS calls, they automatically leverage this enhanced certificate store for verification, which is particularly useful in enterprise environments that rely on custom root CAs deployed via Windows Group Policy. The example performs a simple `requests.get` to show a successful secure connection. Explicit imports are typically not needed for runtime patching, but are shown commented for advanced use cases like PyInstaller.

import requests
import sys
import os

print(f"Attempting to make a secure request...")

try:
    # In a Windows environment with python-certifi-win32 installed,
    # this request should implicitly use the combined CA bundle
    # including Windows system certificates.
    response = requests.get("https://www.google.com", timeout=10)
    response.raise_for_status()
    print(f"Successfully connected to Google (Status: {response.status_code})")
    print("This indicates that SSL/TLS verification worked, potentially leveraging Windows system certificates.")
except requests.exceptions.RequestException as e:
    print(f"Error making request: {e}")
    print("If this is on Windows and behind a corporate proxy, python-certifi-win32 aims to resolve such SSL errors by including system CAs.")

# Example of how it might be explicitly used for PyInstaller (not part of typical quickstart)
# if sys.platform == 'win32':
#     import certifi_win32
#     # This sets an environment variable that 'requests' respects to find the CA bundle.
#     os.environ['REQUESTS_CA_BUNDLE'] = certifi_win32.wincerts.where()
#     certifi_win32.generate_pem()
#     print(f"REQUESTS_CA_BUNDLE set to: {os.environ['REQUESTS_CA_BUNDLE']}")

view raw JSON →