Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TypeError: cannot concatenate 'str' and 'NoneType' objects" on request to get a file. #28

Closed
athanassis opened this issue Jun 12, 2017 · 14 comments
Labels

Comments

@athanassis
Copy link

athanassis commented Jun 12, 2017

I'm trying to download a file which is accessible (via a browser) on this URL:
https://test.sharepoint.com/sites/team/team documents/subfolder/document.docx

I'm using a ClientRequest object with the following code:

url = "https://test.sharepoint.com/sites/team"
username="user@test.com"
password="pass"
ctxAuth = AuthenticationContext(url)
if ctxAuth.acquire_token_for_user(username, password):
    print 'authentication successful, proceeding...'
    request = ClientRequest(ctxAuth)
    requestUrl="{0}/_api/web/getfilebyserverrelativeurl('team documents/subfolder/document.docx')"
    options=RequestOptions(requestUrl.format(url))
    data = request.execute_query_direct(options)

On running this, I'm getting the following trace:

$ python test.py
No handlers could be found for logger "client.office365.runtime.auth.saml_token_provider.SamlTokenProvider.process_service_token_response"
authentication successful, proceeding...
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    data = request.execute_query_direct(options)
  File "/usr/lib/python2.7/site-packages/client/office365/runtime/client_request.py", line 77, in execute_query_direct
    self.context.authenticate_request(request_options)
  File "/usr/lib/python2.7/site-packages/client/office365/runtime/auth/authentication_context.py", line 20, in authenticate_request
    request_options.set_header('Cookie', self.provider.get_authentication_cookie())
  File "/usr/lib/python2.7/site-packages/client/office365/runtime/auth/saml_token_provider.py", line 65, in get_authentication_cookie
    return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa
TypeError: cannot concatenate 'str' and 'NoneType' objects

Is there something wrong on how I use the module?

@jimr
Copy link
Contributor

jimr commented Jun 27, 2017

I had a similar problem because our SharePoint instance is running behind a proxy. I had to subclass the SamlTokenProvider to override the login url (self.sts) and cookie names. I think the issue is that during initialization, the code doesn't check the result of acquire_authentication_cookie so if authentication fails you don't hear about it until the cookies are used.

@kimchirichie
Copy link

kimchirichie commented Jun 29, 2017

I ran into the same issue. It seems like authentication failures are not handled by exceptions. It only bubbles up when cookies are queried. Check your credentials

@alibux
Copy link

alibux commented Jan 23, 2018

Same issue. Checked credentials but issue persists. Any other thoughts? Thanks!

@kimchirichie
Copy link

I ended up using OAuth2Session to get oauth2 authentication and grab data from graph api. its been a while and i no longer remember the exact details.

@alibux
Copy link

alibux commented Jan 23, 2018

Thanks will check it out.

@cigno5
Copy link

cigno5 commented Feb 1, 2018

Hi, I have the same issue, but in my case I think it's because I have sharepoint configured with FormAuthentication method. No way it will work until the proper token provider is implemented

@exlibris
Copy link

I am bumping into this problem too but only if I am using an outlook.com account. I am hoping somebody can explain what is going on behind the scenes and perhaps offer a solution. Here is a brief explanation:

  1. Our SharePoint site is in the cloud (https://mn365.sharepoint.com)
  2. When I make the connection to the site using my State of Minnesota credentials, it connects just fine.
  3. But since I don't want to have my own credentials embedded in my application, I created a "service account" along the lines of "photoImport@outlook.com". This account fails.

What would be the different in authentication between using an outlook.com address and one issued by my organization (in this case firstName.lastName@state.mn.us?

@wontfixthis
Copy link

Same problem here. We're using AD FS for authentication. Till now I didn't found any way to get any information from our sharepoint online server. I tried a lot of libraries but nothing worked for me.

@jvandenbroeck
Copy link

I had the same error because sharepoint was redirecting for authentication to the on-prem STS/ADFS.

We created a new O365 user directly in O365 so it doesn't use the redirect to the on-prem STS/ADFS. This resolved the error 👍

@wontfixthis
Copy link

I switched to sharepy, which runs ootb and covers my conditions

@ponnet
Copy link

ponnet commented Mar 12, 2020

Same here:
No handlers could be found for logger "office365.runtime.auth.saml_token_provider.SamlTokenProvider._process_service_token_response"

Any luck from others?

@vgrem vgrem added the bug label Mar 13, 2020
@henkmuller
Copy link

henkmuller commented Mar 29, 2020

Maybe the following helps to narrow it down further.

I can successfully authenticate on the general sharepoint URL, but not on a URL that is pointing to a specific teams-channel. The following bit of code works fine:

url = "https://COMPANYNAME.sharepoint.com/"
username=raw_input("username: ")
password=raw_input("password: ")
ctx_auth = AuthenticationContext(url=url)
if ctx_auth.acquire_token_for_user(username=username, password=password):

But when I replace the URL with:

url = "https://COMPANYNAME.sharepoint.com/sites/TEAMSCHANNEL/"

then I get the following error::

No handlers could be found for logger "office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_authentication_cookie"

Any work-around appreciated - in my browser I can see both of them just fine.

@BrennanGit
Copy link

We found a workaround for the above use case. Just use the base url for getting the AuthenticationContext. New ClientContext objects can be created using different urls.

base_url = "https://COMPANYNAME.sharepoint.com/"
ctx_auth = AuthenticationContext(url=base_url)
if not ctx_auth.acquire_token_for_user(username=user, password=password):
    sys.exit('Error in getting token - quitting')
url = base_url + "sites/TEAMSCHANNEL/"
ctx = ClientContext(url, ctx_auth)
..
..

@vgrem
Copy link
Owner

vgrem commented Sep 4, 2020

Hey guys!

Since the moment when this issue was reported until now the following improvements/bug fixes have been made in terms of support for SAML-based federated authentication with SharePoint Online:

So, the provided error should no longer occur, just make sure to grab the latest version (2.1.10.1 or above).

@vgrem vgrem closed this as completed Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests