Skip to main content

The HTTP NTLM proxy and/or server authentication library.

Project description

requests-ntlm3

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

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

Installation

pip install requests-ntlm3

Usage

Basic Usage

HttpNtlmAuth extends requests AuthBase, so usage is simple:

import requests
from requests_ntlm3 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_ntlm3 defaults to compatibility level 3 which supports NTLMv2 [only]. You can change the compatibility level as follows:

import requests
from requests_ntlm3 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_ntlm3 import HttpNtlmAuth

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

HTTP CONNECT Usage

When using requests-ntlm3 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_ntlm3 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_ntlm3-6.1.3b1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

requests_ntlm3-6.1.3b1-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file requests_ntlm3-6.1.3b1.tar.gz.

File metadata

  • Download URL: requests_ntlm3-6.1.3b1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.15

File hashes

Hashes for requests_ntlm3-6.1.3b1.tar.gz
Algorithm Hash digest
SHA256 d4d07c8971e49ddacabc4acaac78ffc1cadf0fef6a2c5d516ac5f07a8f4717fe
MD5 ed228fd79c846738cd459e800aa73d6b
BLAKE2b-256 16bb133b383e78081ecadce935ea9c3438e4819dd285b499f6daabc2573a1326

See more details on using hashes here.

File details

Details for the file requests_ntlm3-6.1.3b1-py2.py3-none-any.whl.

File metadata

  • Download URL: requests_ntlm3-6.1.3b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.15

File hashes

Hashes for requests_ntlm3-6.1.3b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23fed752b129a1424fc8e103ffb56fd0a30afff3ce9a6c8bb6ef22b6bf95f66c
MD5 2c7da72adc88550c66e6f79d1d0bedd9
BLAKE2b-256 75f5693ec2354ac85048a1b5e204f366bbf9892767e0124a415689ce1b4853d4

See more details on using hashes here.

Supported by

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