Install & Compatibility
Where this runs
tested against v6.1.3b1 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 38.1MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.0s · import 0.000s · 38MB
36MB installed
● package 36MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HttpNtlmAuth
✓ from requests_ntlm3 import HttpNtlmAuth
✗ from requests_ntlm3 import HttpNtlmAuth
Demonstrates both NTLM server authentication and NTLM proxy authentication. For proxy authentication, ensure `ntlm_proxy_auth=True` is passed to `HttpNtlmAuth`. Environment variables are used for credentials and URLs to keep the example runnable without hardcoding sensitive data. Remember to replace placeholder values with your actual NTLM credentials and URLs.
import requests
import os
from requests_ntlm3 import HttpNtlmAuth
# --- NTLM Server Authentication Example ---
NTLM_USERNAME = os.environ.get('NTLM_SERVER_USERNAME', 'DOMAIN\\user')
NTLM_PASSWORD = os.environ.get('NTLM_SERVER_PASSWORD', 'your_password')
NTLM_SERVER_URL = os.environ.get('NTLM_SERVER_URL', 'http://localhost/protected')
if NTLM_USERNAME and NTLM_PASSWORD and NTLM_SERVER_URL != 'http://localhost/protected':
try:
print(f"Attempting NTLM server auth to {NTLM_SERVER_URL} with user {NTLM_USERNAME.split('\\')[-1]}...")
response = requests.get(
NTLM_SERVER_URL,
auth=HttpNtlmAuth(NTLM_USERNAME, NTLM_PASSWORD)
)
response.raise_for_status()
print(f"NTLM Server Auth Success: Status {response.status_code}, Length {len(response.text)}.")
except requests.exceptions.RequestException as e:
print(f"NTLM Server Auth Failed: {e}")
else:
print("Skipping NTLM server auth example: Set NTLM_SERVER_USERNAME, NTLM_SERVER_PASSWORD, NTLM_SERVER_URL env vars.")
# --- NTLM Proxy Authentication Example ---
PROXY_USERNAME = os.environ.get('NTLM_PROXY_USERNAME', 'DOMAIN\\proxyuser')
PROXY_PASSWORD = os.environ.get('NTLM_PROXY_PASSWORD', 'proxy_password')
PROXY_URL = os.environ.get('NTLM_PROXY_URL', 'http://your_proxy_server:8080')
TARGET_URL_VIA_PROXY = os.environ.get('TARGET_URL_VIA_PROXY', 'http://www.example.com')
if PROXY_USERNAME and PROXY_PASSWORD and PROXY_URL != 'http://your_proxy_server:8080':
proxies = {
"http": PROXY_URL,
"https": PROXY_URL # Use http for https proxy auth as well for NTLM proxies
}
try:
print(f"Attempting NTLM proxy auth via {PROXY_URL} to {TARGET_URL_VIA_PROXY} with user {PROXY_USERNAME.split('\\')[-1]}...")
response = requests.get(
TARGET_URL_VIA_PROXY,
proxies=proxies,
auth=HttpNtlmAuth(PROXY_USERNAME, PROXY_PASSWORD, ntlm_proxy_auth=True)
)
response.raise_for_status()
print(f"NTLM Proxy Auth Success: Status {response.status_code}, Length {len(response.text)}.")
except requests.exceptions.RequestException as e:
print(f"NTLM Proxy Auth Failed: {e}")
else:
print("Skipping NTLM proxy auth example: Set NTLM_PROXY_USERNAME, NTLM_PROXY_PASSWORD, NTLM_PROXY_URL, TARGET_URL_VIA_PROXY env vars.")
Upgrade
Version history
6.1.3b1latest on PyPI · released Feb 19, 2020
Audit
Dependencies
requestsrequiredCore HTTP library dependency.
pyspnegorequiredProvides the underlying SPNEGO/NTLM authentication mechanism.