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

前端 未结 1 738
一整个雨季
一整个雨季 2021-01-06 06:44

I have a script that checks a SharePoint list for a specific file revision and returns the result. This works well, but currently my authorisation method requires me to incl

相关标签:
1条回答
  • 2021-01-06 07:27

    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())
    
    0 讨论(0)
提交回复
热议问题