Skip to content

Instantly share code, notes, and snippets.

@cordylus
Last active August 28, 2015 19:32
Show Gist options
  • Save cordylus/4e65126e6bc48d2bd74d to your computer and use it in GitHub Desktop.
Save cordylus/4e65126e6bc48d2bd74d to your computer and use it in GitHub Desktop.
DEMO: Python - Authenticate Against NTLM
# A simple demonstration of authenticating against ntlm.
# In this case we needed to be certain that we could access
# the SharePoint REST API through python.
import requests
from requests_ntlm import HttpNtlmAuth
def rest_test(domain, user, password, url):
# create a session
session = requests.Session()
# add ntlm auth to session
# requests-kerberos also available in pypi if needed
auth = auth=HttpNtlmAuth(domain + '\\' + user, password, session)
# send a GET using the session and auth
response = session.get(url, auth=auth)
# explicitly close the connection
response.connection.close()
#send requests as long as the session stays open.
print response.content
# explicitly close the session
session.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment