Skip to main content

The HTTP NTLM proxy and/or server authentication library.

Project description

requests-ntlm2

Build Status codecov Python Version PyPI Status Downloads Licence

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

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)

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')

HTTPS CONNECT Usage

When using requests-ntlm2 to create SSL proxy tunnel via HTTPS 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

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

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

url = 'http:/foobar.com'

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

response = session.get(url)

Installation

pip install requests-ntlm2

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.0.8.tar.gz (9.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: requests_ntlm2-6.0.8.tar.gz
  • Upload date:
  • Size: 9.9 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.41.1 CPython/2.7.15

File hashes

Hashes for requests_ntlm2-6.0.8.tar.gz
Algorithm Hash digest
SHA256 dbdae3081fb9271bab9fa7b9e324a0c16c1bbecb5e145e5ef5ca2b6ccb6bb14c
MD5 510d1d3b5a5448a1f28e95cfa2d5f474
BLAKE2b-256 e01d5c9b007d806b1188076add588c3612e946ea75314a4dc31cb47492ef7393

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