1

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 ?

1 Answer 1

5

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"]))
Sign up to request clarification or add additional context in comments.

1 Comment

I tried this code now but I think it does not work anymore. Are there any new solution for this job?

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.