The original requests_ntlm2.compatibility.NtlmCompatibility import path also works.
Basic Usage
HttpNtlmAuth extends requests AuthBase, so usage is simple:
import requests
from requests_ntlm2.auth import HttpNtlmAuth
auth=HttpNtlmAuth('domain\\username','password')
requests.get("http://ntlm_protected_site.com", auth=auth)
Changing NTLM compatibility level
See this MS doc on LM compatibility levels. requests_ntlm2 defaults to
compatibility level 3 which supports NTLMv2 [only]. You can change the compatibility level as follows:
HttpNtlmAuth can be used in conjunction with a Session in order to
make use of connection pooling. Since NTLM authenticates connections,
this is more efficient. Otherwise, each request will go through a new
NTLM challenge-response.
When using requests-ntlm2 to create SSL proxy tunnel via
HTTP CONNECT, the so-called
"NTLM Dance" - ie, the NTLM authentication handshake - has to be done at the lower level
(at the http.client level) during tunnel creation. Use the HttpNtlmAdapter
and requests session. This HttpNtlmAdapter is responsible for sending proxy auth information
downstream.
The package supports Python 3.6 and later. Install uv
and just to run the development commands.
uv sync --locked --python 3.13
just lint
just test
just build
Run just ruff, just bandit, just typecheck, or just imports for an individual check.
just test runs pytest with coverage, starts and stops the local test server,
and enables OpenSSL's legacy provider for the NTLM tests when available. The
test recipe uses Bash.
The separate functional suite requires Windows IIS. See
tests/functional/setup_iis.ps1 for its setup.
Alternatives
Use instead of requests-ntlm2: tools that do the same job, closest first.