Registry / http-networking / ndg-httpsclient

ndg-httpsclient

JSON →
library0.5.1pypypi✓ verified 24d ago

ndg-httpsclient provides enhanced HTTPS support for Python's standard library modules `httplib` and `urllib2` (Python 2) or `http.client` and `urllib.request` (Python 3) using PyOpenSSL. It allows for advanced SSL/TLS features like Server Name Indication (SNI) and robust peer certificate verification, extending capabilities beyond the default standard library implementation. The current version is 0.5.1, with a relatively slow release cadence focused on compatibility and critical fixes.

pip install ndg-httpsclient
INSTALL
IMPORT
SIG · NDG-HTTPSCLIENT
N
ndg-httpsclient
http-networkingpythonv0.5.1
Install
2.7s avg
Import
461ms
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.466s · 36.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.456s · 37MB
35MB installed
● package 35MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

open_url
from ndg.httpsclient.utils import open_url
ServerSSLCertVerification
from ndg.httpsclient.ssl_peer_verification import ServerSSLCertVerification
SubjectAlternativeNameMatcher
from ndg.httpsclient.ssl_peer_verification import SubjectAlternativeNameMatcher

This quickstart demonstrates using `ndg-httpsclient`'s `open_url` utility to make an HTTPS request. This function internally leverages the PyOpenSSL-enhanced `HTTPSHandler` that the library integrates into Python's standard HTTP client modules. For more advanced use, like client certificate authentication or custom CA bundles, additional arguments can be passed to `open_url`.

import sys import ssl # PyOpenSSL is a dependency that ndg-httpsclient leverages from OpenSSL import SSL # ndg-httpsclient patches these modules, so they should benefit from its enhancements if sys.version_info[0] >= 3: import urllib.request as request_mod import http.client as http_client_mod else: import urllib2 as request_mod import httplib as http_client_mod # The primary utility for direct use is open_url from ndg.httpsclient.utils import open_url # For this example, we'll try a common HTTPS URL. # In a real-world scenario, you might pass specific client certificates (c, k) # or a custom CA bundle (ca) for peer verification. target_url = "https://www.google.com" print(f"Attempting to connect to {target_url} using ndg-httpsclient's open_url...") try: # open_url utilizes the PyOpenSSL-backed HTTPS handling provided by ndg-httpsclient # For more robust verification, you'd provide `ca='path/to/ca-bundle.pem'` response = open_url(target_url) print(f"Connection successful!") print(f"HTTP Status Code: {response.getcode()}") print(f"Content-Type: {response.info()['Content-Type']}") # Read and decode a small part of the content to demonstrate success # Do not read full content for quickstart to avoid large output content_snippet = response.read(200).decode('utf-8', errors='ignore') print(f"Partial Content: {content_snippet}...") except SSL.Error as e: print(f"SSL Error during connection: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingSupport for Python 2.6 and Python 3.3 was dropped in version 0.5.1. Users on these End-of-Life Python versions must use an older `ndg-httpsclient` version or upgrade their Python environment.
fix
Upgrade Python to a supported version (e.g., Python 3.6+) or pin `ndg-httpsclient<0.5.1`.
affects: >=0.5.1
gotchandg-httpsclient primarily enhances Python's lower-level `httplib`/`urllib2` (Python 2) or `http.client`/`urllib.request` (Python 3) modules with PyOpenSSL. It is not a general-purpose HTTP client like `requests` and requires understanding of the underlying standard library modules for effective use. It's often used in scenarios needing fine-grained SSL/TLS control.
fix
Understand that this library is a low-level enhancement for specific SSL/TLS requirements, not a replacement for higher-level HTTP client libraries.
affects: All
gotchaVersion 0.4.2 introduced a bug in the `ndg.httpsclient.utils.open_url` function (a duplicate open call). This bug was fixed in version 0.4.3. Importantly, this specific bug *did not affect* the core `httplib` and `urllib2` interfaces that the package patches, only the higher-level `open_url` utility.
fix
If relying on `ndg.httpsclient.utils.open_url`, ensure you are on version 0.4.3 or higher.
affects: 0.4.2
deprecatedWhile `ndg-httpsclient` provides Python 3 compatibility, the standard library modules it enhances (`urllib.request`, `http.client`) are often superseded by higher-level, more user-friendly libraries like `requests` for general-purpose HTTP communication. This library remains relevant for niche applications requiring deep PyOpenSSL integration.
fix
For most new HTTP-related projects, consider `requests`. Use `ndg-httpsclient` when explicit PyOpenSSL control or compatibility with existing standard library code is a strict requirement.
affects: All
breakingThe `ndg.httpsclient.utils.open_url` function's signature changed in version 0.5.0, now requiring a `config` argument. Calls to `open_url()` without this argument will raise a `TypeError`.
fix
Update calls to `ndg.httpsclient.utils.open_url` to provide the `config` argument, or pin `ndg-httpsclient<0.5.0` if the older signature is required.
affects: >=0.5.0
Errors
Common errors & fixes
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
This error indicates that the client could not verify the server's SSL certificate, often due to missing or outdated CA certificates, hostname mismatch, or an insufficient SSL/TLS configuration in older Python environments that ndg-httpsclient aims to enhance.
fix
Ensure `pyOpenSSL`, `ndg-httpsclient`, and `pyasn1` are installed and up-to-date using `pip install --upgrade pyOpenSSL ndg-httpsclient pyasn1` to provide more robust SSL/TLS capabilities, especially for SNI and certificate verification. Updating system CA certificates may also be necessary.
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
This warning (often accompanied by `SNIMissingWarning`) occurs on Python versions older than 2.7.9/2.7.10, where the standard library's SSL module lacks full features like Server Name Indication (SNI) or a true `SSLContext` object, leading to potential security vulnerabilities or connection failures.
fix
Install `pyOpenSSL`, `ndg-httpsclient`, and `pyasn1` using `pip install pyOpenSSL ndg-httpsclient pyasn1` to provide enhanced SSL/TLS capabilities, including SNI support, for older Python environments.
ImportError: No module named OpenSSL
This error means the `pyOpenSSL` library, a fundamental dependency for `ndg-httpsclient` to function by providing advanced SSL/TLS features, is either not installed or not accessible in the current Python environment.
fix
Install `pyOpenSSL` using pip: `pip install pyOpenSSL`. On some systems, development headers for OpenSSL (`libssl-dev` on Debian/Ubuntu, `openssl-devel` on Fedora) and `libffi-dev` might be required before installing `pyOpenSSL` and its dependencies.
SSL handshake failed
This general error indicates that the initial negotiation between the client (using `ndg-httpsclient` for enhanced SSL) and the server to establish a secure SSL/TLS connection failed, which can be due to various reasons like protocol mismatches, unsupported ciphers, server misconfiguration, or lack of proper SNI support from the client.
fix
Ensure `pyOpenSSL`, `ndg-httpsclient`, and `pyasn1` are installed and up-to-date (`pip install --upgrade pyOpenSSL ndg-httpsclient pyasn1`) to provide robust SSL/TLS capabilities and SNI support. Verify the server's SSL/TLS configuration for compatibility and ensure the client platform's OpenSSL libraries are correctly configured.
Upgrade
Version history
0.5.1latest on PyPI · released Jul 23, 2018
Audit
Dependencies
pyopensslrequiredCore functionality relies on PyOpenSSL for SSL/TLS operations.
cryptographyoptionalA transitive dependency of PyOpenSSL.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources