Search code examples
pythonsharepointntlm

Having trouble with python's ntlm auth


Based on this template from the requests_ntlm docs:

import requests
from requests_ntlm import HttpNtlmAuth

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

... I have the following code that attempts to connect to a SharePoint page:

import requests
from requests_ntlm import HttpNtlmAuth

def main():

    response = requests.get('https://my-site-url.com', auth='https://my-site-url.com\\MY_USER_NAME', 'MY_PASS')
    print response


if __name__ == "__main__":
            main()

Unfortunately, I'm getting a 401 response.

I assumed the "domain" referred to in the docs is the same as 'https://my-site-url.com'. Is that correct?

Moreover, is there anything glaringly wrong with my syntax here?

I should note that my curl request works, so I know there's nothing wrong with my user name and password.

curl -f -v --ntlm -u MY_USER_NAME https://my-site-url.com

Solution

  • I got it to work using:

    auth=HttpNtlmAuth("\\MY_USER_NAME", "MY_PASS")