Authorise with current user credentials for Python script accessing SharePoint list using NTLM

为君一笑 提交于 2019-12-01 08:46:56

There is an open pull request for the requests_ntlm library here to merge in SSPI authentication for Windows users. I had to make a few edits to the code for it to be functional, but it is working for me.

You'll first need to install requests and requests_ntlm, then modify the "requests_ntlm\__init__.py" package file (in your Python "Lib\site-packages" folder if on Windows) to resemble the following:

from .requests_ntlm import HttpNtlmAuth
from .requests_ntlmsspi import HttpNtlmSspiAuth

__all__ = ('HttpNtlmAuth', 'HttpNtlmSspiAuth')

Next, add the "requests_ntlmsspi.py" file (from the link above) to the "requests_ntlm" package folder.

You should then be able to authenticate using the current user's credentials as follows:

import requests
from requests_ntlm import HttpNtlmAuth, HttpNtlmSspiAuth

requests.get(site_url, auth=HttpNtlmSspiAuth())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!