1

I am trying to connect to Sharepoint using the following code. It was working previously however it has suddenly stopped working, and is now showing the following error:

 File "C:\Users\Documents\Anaconda2\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 67, in get_authentication_cookie
return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa

TypeError: cannot concatenate 'str' and 'NoneType' objects

ctx_auth = AuthenticationContext(url)

if ctx_auth.acquire_token_for_user(username, password):

print("Authentication with SharePoint was successful: {0}".format(
        ctx_auth.acquire_token_for_user(username, password)))

ctx = ClientContext(url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print "SharePoint Site: {0}".format(web.properties['Title'])

else: print ctx_auth.get_last_error()

It fails on this line:

ctx.execute_query()

1 Answer 1

1

I have been using sharepy library as an alternative solution in connecting to Sharepoint.
Use pip install sharepy to install the module.

import sharepy
from sharepy import connect
from sharepy import SharePointSession

server='youraccount.sharepoint.com'
user='[email protected]'
password='password'

s = sharepy.connect(server,user,password) 

# Example request to Sharepoint
headers = {'accept': 'application/atom+json'} #json can be changed to xml
r = s.get("https://youraccount.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('path_to_your_folder/')/Files", headers=headers)

It should print out the following on successful authentication:

Requesting security token...Requesting access cookie... Authentication successful

Sign up to request clarification or add additional context in comments.

4 Comments

I keep getting this error: "'NoneType' object has no attribute 'group'"
It throws an error while connecting: sharepy.errors.AuthError: Unknown authentication error
I get the same error, any solution yet !!! @Shubham
@YaserSakkaf Yeah, you can generate a client ID and client secret then use that for authentication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.