Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing sharepoint site in python with windows authentication

I am trying to work with a sharepoint site that use my windows authentication. I can use the requests module to access the site but it requires I explicitly state my windows password.

import requests
from requests_ntlm import HttpNtlmAuth

SITE = "https://sharepointsite.com/"
PASSWORD = "pw"
USERNAME = "domain\\user"

response = requests.get(SITE, auth=HttpNtlmAuth(USERNAME,PASSWORD))
print response.status_code

Is there a way for Python to access the site through windows authentication so I don't have to provide my password? It seems like this might be possible through requests_nltm but I can't work out how.

like image 251
Tim S_ Avatar asked Sep 10 '14 11:09

Tim S_


People also ask

How do I access SharePoint without authentication?

You need to enable exteranal sharing in SharePoint Online. Please go to SharePoint Online admin center-> policies-> Sharing. Set the level to "Anyone." Thus you could share the wiki page to anyone with the link.

What is Sharepy in Python?

SharePy - Simple SharePoint Online authentication for Python. This module will handle authentication for your SharePoint Online/O365 site, allowing you to make straightforward HTTP requests from Python.

What is SharePlum?

SharePlum is an easier way to work with SharePoint services. It handles all of the messy parts of dealing with SharePoint and allows you to write clean and Pythonic code.


2 Answers

If you don't want to explicitly state your windows password you could use the getpass module:

import requests
from requests_ntlm import HttpNtlmAuth
import getpass

SITE = "https://sharepointsite.com/"
USERNAME = "domain\\user"

response = requests.get(SITE, auth=HttpNtlmAuth(USERNAME, getpass.getpass()))
print response.status_code

This way you don't have to store you password in plain text.

Looking at the code for the requests_ntlm there isn't a way to use it without supplying your password or the hash of your password to HttpNtlmAuth

like image 179
Noelkd Avatar answered Oct 07 '22 11:10

Noelkd


The accepted answer still uses a stored password. An option to use integrated authentication via the Windows SSPI interface would be the following:

import requests
from requests_negotiate_sspi import HttpNegotiateAuth

cert = 'path\to\certificate.cer'
 
response = requests.get(
    r'http://mysharepoint.com/_api',
    auth=HttpNegotiateAuth(),
    verify=cert)

print(response.status_code)

See here for more information.

like image 23
Stephan Avatar answered Oct 07 '22 11:10

Stephan