2

This is a follow up question from the below answer:

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

I am trying to interface with a SharePoint list without passing or hard-coding a password in my script.

The solution provided in the previous answer works successfully with the requests library, however I am unable to integrate it into the urllib2 function that I use to interface with SharePoint.

The function below currently works with a hard-coded password, but I would prefer to use SSPI authentication so as not to embed the pw in the script.

def read_sharepoint_list(current_project):
    username = "Domain\\user.name"
    password = "my_password"

    # the sharepoint info
    site_url = "http://SharePoint/"
    list_name = "My List"

    # an opener for the NTLM authentication
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, site_url, username, password)
    auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)

    # create and install the opener
    opener = urllib2.build_opener(auth_NTLM)
    urllib2.install_opener(opener)

I have focused my attempts to integrate on the passman.addpassword() component of the below function with no luck.

I have replaced the password HttpNtlmSspiAuth() call. Also have replaced with the full requests string: requests.get(site_url, auth=HttpNtlmSspiAuth()). No luck with either.

I have also tried to engage with the auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman) line, but I am out of my depth. Reviewing the NTLM documentation has thus far not yielded a solution.

Your thoughts and suggestions are much appreciated.

Community
  • 1
  • 1
jdg
  • 547
  • 6
  • 15

0 Answers0