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)
Community
  • 1
  • 1
j doe
  • 233
  • 6
  • 19
  • 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'}` – Håken Lid May 13 '16 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 – j doe May 17 '16 at 17:46

1 Answers1

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!!

Nishant Patel
  • 1,334
  • 14
  • 22