Skip to main content

The HTTP NTLM proxy and/or server authentication library.

Project description

requests-ntlm2

NTLM authentication plugin for Requests

Build Status codecov Python Version PyPI Status Downloads Licence Code Style: Black

requests-ntlm2, which is based on requests-ntlm, allows for HTTP NTLM authentication using the requests library.

Installation

pip install requests-ntlm2

Usage

Basic Usage

HttpNtlmAuth extends requests AuthBase, so usage is simple:

import requests
from requests_ntlm2 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:

import requests
from requests_ntlm2 import HttpNtlmAuth, NtlmCompatibility

username = 'domain\\username'
password = 'password123'
ntlm_compatibility = NtlmCompatibility.LM_AND_NTLMv1_WITH_ESS  # => level 1
auth=HttpNtlmAuth(username, password, ntlm_compatibility=ntlm_compatibility)

requests.get("http://ntlm_protected_site.com", auth=auth)

Using with Requests Session

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.

import requests
from requests_ntlm2 import HttpNtlmAuth

session = requests.Session()
session.auth = HttpNtlmAuth('domain\\username','password')
session.get('http://ntlm_protected_site.com')

HTTP CONNECT Usage

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 httplib level) at tunnel-creation step. This means that you should use the HttpNtlmAdapter and requests session. This HttpNtlmAdapter is responsible for sending proxy auth information downstream.

Here is a basic example:

import requests
from requests_ntlm2 import (
    HttpNtlmAuth,
    HttpNtlmAdapter,
    NtlmCompatibility
)

username = '...'
password = '...'
proxy_ip = '...'
proxy_port = '...'

proxies = {
    'http': 'http://{}:{}'.format(proxy_ip, proxy_port),
    'https': 'http://{}:{}'.format(proxy_ip, proxy_port)
}

ntlm_compatibility = NtlmCompatibility.NTLMv2_DEFAULT

session = requests.Session()
session.mount(
    'https://',
    HttpNtlmAdapter(
        username,
        password,
        ntlm_compatibility=ntlm_compatibility
    )
)
session.mount(
    'http://',
    HttpNtlmAdapter(
        username,
        password,
        ntlm_compatibility=ntlm_compatibility
    )
)
session.auth = HttpNtlmAuth(
    username,
    password,
    ntlm_compatibility=ntlm_compatibility
)
session.proxies = proxies

response = session.get('http:/foobar.com')

Requirements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_ntlm2-6.2.8.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_ntlm2-6.2.8-py2.py3-none-any.whl (13.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file requests_ntlm2-6.2.8.tar.gz.

File metadata

  • Download URL: requests_ntlm2-6.2.8.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.0 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/2.7.15

File hashes

Hashes for requests_ntlm2-6.2.8.tar.gz
Algorithm Hash digest
SHA256 3e69bd94de6f35cec0f798c2672854c2a2532d1c8c9066d13aa3aeed9aae5949
MD5 ce8bf938f03336ccbf48f451124e2820
BLAKE2b-256 87c282ee8955c27baca054893489e815a3db8b7322e1e24157a55e481c469a4a

See more details on using hashes here.

File details

Details for the file requests_ntlm2-6.2.8-py2.py3-none-any.whl.

File metadata

  • Download URL: requests_ntlm2-6.2.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.0 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/2.7.15

File hashes

Hashes for requests_ntlm2-6.2.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e3cde3bd8e43ab097c80bbff5986a9613e17e123592c04f0619841404dd911b4
MD5 fcfcd638e4f05806d7651dd6ea1be22a
BLAKE2b-256 b4c353c64708204f7d03e8ae85b45c5079aaa6210746804b3cd4494fc690d68b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page