Reputation: 233
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)
Upvotes: 0
Views: 4955
Reputation: 1406
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!!
Upvotes: 1