Brinley
Brinley

Reputation: 721

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

Upvotes: 1

Views: 3951

Answers (2)

Brinley
Brinley

Reputation: 721

I got it to work using:

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

Upvotes: 0

mspiller
mspiller

Reputation: 3847

If your curl call works without the domain in front of the username, you should be able to omit it in your python code.

Try

auth=HttpNtlmAuth('MY_USERNAME','MY_PASS')

Upvotes: 2

Related Questions