Reputation: 19
I have full access to the resource I would like to connect to the Microsoft.sharepoint.c0m site lists.
I would like to know what is the easiest way to pull or upload the data from sharepoint list in python? I am getting error code 403 with this code:
import requests
from requests_ntlm import HttpNtlmAuth
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
auth = HttpNtlmAuth('username', 'password')
r = requests.get("https://sharepoint.com/_api/Web/lists/GetByTitle('ListName')/items",
verify=False,
auth=auth,
)
Why am I getting error code 403 ?
Upvotes: 1
Views: 13614
Reputation: 59348
HttpNtlmAuth is supposed to be utilized via HTTP NTLM authentication which is not supported in SharePoint Online.
Instead you could consider Office365-REST-Python-Client library.The following example demonstrates how to authenticate via user credentials and read list items in SharePoint Online:
from office365.runtime.auth.authentication_context import AuthenticationContext
ffrom office365.sharepoint.client_context import ClientContext
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
list_object = ctx.web.lists.get_by_title(listTitle)
items = list_object.get_items()
ctx.load(items)
ctx.execute_query()
for item in items:
print("Item title: {0}".format(item.properties["Title"]))
Upvotes: 5