0
votes

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='[email protected]', 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='[email protected]', password=pwd):
        ctx = ClientContext(settings['url'], ctxAuth)
        print("Authentication is success")
    else:
        print(ctxAuth.get_last_error())
1
Hey, are you sure that SP server is available? - Alex
Yes, I am able to access it from browser - Murali
Your Authentication happen properly.if not check your credentials - Jaynesh Sharma

1 Answers

0
votes

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('[email protected]', 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