0

I have tried basic auth while following this link. I have also followed this question to get my code below using NTLM auth. I am still being thrown a 401 error. Is this an outdated way of pulling SharePoint lists or is there something wrong with my code?

import requests

from requests_ntlm import HttpNtlmAuth

response = requests.get("https://example.com/_api/web/...", auth=HttpNtlmAuth('username', 'password'))

print(response.status_code)
2
  • It's the server that reponds with a 401 status. What is the response body? print(response.text) Are you sure the server uses ntlm? Have you been able to connect using curl or any other means? Have you tried using a request accept header. {'accept': 'application/json'} Commented May 13, 2016 at 22:08
  • I am sure the server uses ntlm, and we have been able to connect using jquery. When i put the response.text I get no output. I will try to add the accept header Commented May 17, 2016 at 17:46

1 Answer 1

1

Your approach is good enough.

Try few changes as below:

import requests
from requests_ntlm import HttpNtlmAuth

url="https://sharepointexample.com/"
user, pwd = "username", "pwd"
headers = {'accept': 'application/json;odata=verbose'}
r = requests.get(url, auth=HttpNtlmAuth(user, pwd), headers=headers)
print(r.status_code)
print(r.content)

Here you wont encounter 401 response, instead you will get Response as 200, which indicates the HTTP response is OK!!..

Next the content will show you the list options which you can parse as html page.

Hope this helps!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.