Last active
August 28, 2015 19:32
-
-
Save cordylus/4e65126e6bc48d2bd74d to your computer and use it in GitHub Desktop.
DEMO: Python - Authenticate Against NTLM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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