Registry / http-networking / requests-ntlm

requests-ntlm

JSON →
library1.3.0pypypi✓ verified 27d ago

This package enables HTTP NTLM authentication for the popular Python requests library. It provides a simple `HttpNtlmAuth` class that integrates seamlessly with `requests.Session` for handling NTLM challenges. The current version is 1.3.0, and it follows an active maintenance cadence with releases addressing compatibility, security, and minor enhancements.

pip install requests-ntlm
INSTALL
IMPORT
SIG · REQUESTS-NTLM
R
requests-ntlm
http-networkingpythonv1.3.0
Install
3.1s avg
Import
739ms
Disk
38MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · 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.760s · 39.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.718s · 40MB
38MB installed
● package 38MB
Code
Verified usage

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

HttpNtlmAuth
from requests_ntlm import HttpNtlmAuth

This quickstart demonstrates how to use `HttpNtlmAuth` with a `requests.Session`. It's crucial to correctly format the username (e.g., `DOMAIN\username` or `user@domain.com`) and provide the corresponding password. The example uses environment variables for sensitive data for security and convenience.

import requests from requests_ntlm import HttpNtlmAuth import os # Replace with your NTLM-protected URL url = os.environ.get('NTLM_TEST_URL', 'http://ntlm-protected-server.local/api/') # Replace with your NTLM credentials username = os.environ.get('NTLM_USERNAME', 'DOMAIN\\user') password = os.environ.get('NTLM_PASSWORD', 'your_password') try: session = requests.Session() session.auth = HttpNtlmAuth(username, password) response = session.get(url) response.raise_for_status() # Raise an exception for bad status codes print(f"Successfully authenticated to {url}") print("Response content (first 200 chars):\n", response.text[:200]) except requests.exceptions.RequestException as e: print(f"Error connecting or authenticating: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingStarting with v1.3.0, `requests-ntlm` will now explicitly throw an exception (`requests.exceptions.HTTPError` or similar, potentially wrapped) in case of access denied, rather than silently returning an unsuccessful response or handling it internally. This changes error handling behavior.
fix
Ensure your code explicitly catches and handles exceptions for HTTP errors or access denied scenarios. Review code that previously might have processed an empty or error response without an explicit exception.
affects: >=1.3.0
gotchaVersions prior to `v1.3.0` might suffer from issues related to type annotations or compatibility with certain `pyspnego` versions, potentially leading to runtime errors or incorrect behavior.
fix
Upgrade to `requests-ntlm==1.3.0` or newer to ensure correct type annotation and `pyspnego` compatibility. This version sets the correct minimum `pyspnego` version (>=0.11.1).
affects: <1.3.0
gotchaThe library underwent a significant internal migration to use `PySPNEGO` as its underlying NTLM provider in `v1.2.0`. While the public API (`HttpNtlmAuth`) was designed to remain compatible, subtle behavioral changes or new dependency requirements (`pyspnego`) might affect existing integrations, especially in edge cases or complex NTLM environments.
fix
Verify that `pyspnego` is correctly installed and meets the minimum version requirements. Test your NTLM integrations thoroughly after upgrading to v1.2.0 or newer.
affects: >=1.2.0
gotchaVersions of `requests-ntlm` prior to `v1.1.0` had issues correctly parsing User Principal Names (UPN) when passed as usernames (e.g., `user@domain.com`). This could lead to authentication failures.
fix
Upgrade to `requests-ntlm==1.1.0` or newer if you are using UPNs for NTLM authentication. Alternatively, ensure your username is in the `DOMAIN\user` format for older versions.
affects: <1.1.0
breaking`requests-ntlm` explicitly requires Python 3.8 or newer. Attempts to install or run it on older Python versions will fail.
fix
Ensure your project's Python environment is running Python 3.8 or a later version. Use a tool like `pyenv` or virtual environments to manage Python versions.
affects: <3.8 (Python)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'requests_ntlm'
The `requests-ntlm` package has not been installed in the current Python environment.
fix
pip install requests-ntlm
ImportError: cannot import name 'HttpNtlmAuth' from 'requests.auth'
`HttpNtlmAuth` is provided by the separate `requests-ntlm` package, not the standard `requests.auth` module.
fix
from requests_ntlm import HttpNtlmAuth
TypeError: __init__ missing 1 required positional argument: 'username'
The `HttpNtlmAuth` constructor requires both a username and a password as positional arguments.
fix
HttpNtlmAuth('your_username', 'your_password')
ModuleNotFoundError: No module named 'requests_ntlm.requests_ntlm'
The `HttpNtlmAuth` class is exposed directly at the top-level `requests_ntlm` package, not within a submodule named `requests_ntlm.requests_ntlm`.
fix
from requests_ntlm import HttpNtlmAuth
Upgrade
Version history
1.3.0latest on PyPI · released Jun 9, 2024
Audit
Dependencies
requestsrequiredCore HTTP library for which NTLM authentication is provided.
pyspnegorequiredUnderlying library for SPNEGO/NTLM negotiation, introduced as a core dependency in v1.2.0.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
requests-ntlm — pip install requests-ntlm · libregistry