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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With