0

I am working on a report automation project, where I need to download excel files automatically from a share point location. I tried some examples referring to Python - Download files from SharePoint site but getting below error within imported library function. Please let me know, what I am missing here.

Error:

Traceback (most recent call last):
File "worklod_report.py", line 66, in
if ctxAuth.acquire_token_for_user(username='murali.pandiyan@xyz.com', password=pwd):
File "C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site- packages\office365\runtime\auth\authentication_context.py", line 18, in acquire_token_for_user return self.provider.acquire_token()
File "C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 57, in acquire_token
self.acquire_service_token(options)
File "C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 88, in acquire_service_token
token = self.process_service_token_response(response)
File "C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 119, in process_service_token_response
return token.text
AttributeError: 'NoneType' object has no attribute 'text'

Python code:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
import getpass

if __name__ == '__main__':
    ctxAuth = AuthenticationContext(url='https://internal.abc.net/sites/Compute/')
    print("Enter Password:")
    pwd=getpass.getpass()
    if ctxAuth.acquire_token_for_user(username='murali.pandiyan@xyz.com', password=pwd):
        ctx = ClientContext(settings['url'], ctxAuth)
        print("Authentication is success")
    else:
        print(ctxAuth.get_last_error())
Murali
  • 11
  • 1
  • 5

1 Answers1

0

The following code snippet for your reference.

if __name__ == '__main__':
    ctxAuth = AuthenticationContext('https://internal.abc.net/sites/Compute/')
    print("Enter Password:")
    pwd=getpass.getpass()
    if ctxAuth.acquire_token_for_user('murali.pandiyan@xyz.com', pwd):
        ctx = ClientContext(settings['url'], ctxAuth)
        print("Authentication is success")
    else:
        print(ctxAuth.get_last_error())

Check the authentication source code here: authentication_context.py

And the source code of file download is here: file_operations.py

LZ_MSFT
  • 4,079
  • 1
  • 8
  • 9
  • Thanks for the response. On investigating the issue, found out that PowerShell script is able to authenticate and download the files from SharePoint. PS script converts the plain text password into secure string and then passes it to the authentication method. – Murali Dec 04 '19 at 09:16
  • Tried to replicate the same in python using **py-securestring** module but sample doesn't seem to be working. Please advice on how to proceed with securestring authentication – Murali Dec 04 '19 at 10:14