Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

AttributeError: 'NoneType' object has no attribute 'text'

Open archenroot opened this issue 6 years ago • 14 comments

Hi, I am facing same issue as #118 , but cannot figure out how to change url in my case, tried already combinations.

When I open Sharepoint I get to this url: https://collaboration.{domain}.{company}.{suffix}/Pages

When I access my project I get to following url: https://collaboration.{domain}.{company}.{suffix}/sites/{project-name}/SharedDocuments

I tried following combinations: https://collaboration.{domain}.{company}.{suffix} https://collaboration.{domain}.{company}.{suffix}/Pages https://collaboration.{domain}.{company}.{suffix}/sites/{project-name} https://collaboration.{domain}.{company}.{suffix}/sites/{project-name}/ShareDocuments

None works... any ideas?

archenroot avatar Sep 12 '19 14:09 archenroot

We have our system integrated via OneLogin system...

archenroot avatar Sep 12 '19 14:09 archenroot

Greetings!

indeed, url format might be confusing when addressing resources in SharePoint/Office365.

ClientContext class accepts as a first argument the url of a site, for example:

in case of url https://collaboration.{domain}.{company}.{suffix}/Pages site url corresponds to https://collaboration.{domain}.{company}.{suffix}/

in case

https://collaboration.{domain}.{company}.{suffix}/sites/{project-name}/ShareDocuments

site url is:

https://collaboration.{domain}.{company}.{suffix}/sites/{project-name}/

vgrem avatar Sep 12 '19 14:09 vgrem

@vgrem - thx for quick answer.

I tried all combinations...It doesn't work, still same issue, I think I lack some permissions :-) or we use some non-standard security authentication...? But don't know how to check these...

I tried to use directly requests module: r = requests.get(url, auth=HttpNtlmAuth('domain\user',password), headers=headers)

And gets 403. .... but of course I can in browser access the items without any issue...

archenroot avatar Sep 12 '19 14:09 archenroot

Hi,

I'm getting the same error while calling the authentication method. I'm directly passing the username and password, not using settings.py

Traceback (most recent call last): File "sharepoint_file_operation.py", line 82, in if ctx_auth.acquire_token_for_user(username, password): File "/Library/Python/2.7/site-packages/office365/runtime/auth/authentication_context.py", line 18, in acquire_token_for_user return self.provider.acquire_token() File "/Library/Python/2.7/site-packages/office365/runtime/auth/saml_token_provider.py", line 57, in acquire_token self.acquire_service_token(options) File "/Library/Python/2.7/site-packages/office365/runtime/auth/saml_token_provider.py", line 88, in acquire_service_token token = self.process_service_token_response(response) File "/Library/Python/2.7/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'

Actual Web URL : https://intranet.{company}.com/sites/abc/xyz/Shared%20Documents/Forms/AllItems.aspx?RootFolder="........."

URL combination that didn't work, https://intranet.{company}.com/sites/abc/xyz/Shared%20Documents https://intranet.{company}.com/sites/abc/xyz/ https://intranet.{company}.com/sites/abc

mgaurav92 avatar Sep 13 '19 08:09 mgaurav92

The same problem here. Can anyone support?

victorcamposm avatar Oct 01 '19 13:10 victorcamposm

I am facing same issue can anyone help me?

achyutaparida avatar Dec 03 '19 10:12 achyutaparida

Same problem here.

pentatoma avatar Dec 03 '19 13:12 pentatoma

I'm facing the same problem

KasperSvendsen avatar Dec 05 '19 09:12 KasperSvendsen

Same issue here .... anyone find a solution?

macthebadazz avatar Dec 09 '19 17:12 macthebadazz

Same issue!

josh-flori avatar Jan 06 '20 19:01 josh-flori

just to ensure. MFA is not supported and will lead to auth issues.

beliaev-maksim avatar Aug 08 '21 11:08 beliaev-maksim

facing same issue with below code

from office365.runtime.auth.user_credential import UserCredential from office365.sharepoint.client_context import ClientContext

site_url = "https://XXXX-my.sharepoint.com/personal/XXXXXXXX/" username_env = '[email protected]' password_env = 'XXXXXX' relativeUrl = "Documents/XXXXXXX/"

ctx = ClientContext(site_url).with_credentials(UserCredential(username_env, password_env)) web = ctx.web ctx.load(web) ctx.execute_query()

Above code is working in my (windows) local system but while running in docker it gives below error. 'NoneType' object has no attribute 'text'

Anyone found solution for this ?

Dhyanesh97 avatar Aug 23 '21 14:08 Dhyanesh97

same issue as you @Dhyanesh97.

When I run in docker or try to use this file upload functionality as part of an API and then test the endpoint with postman, I get " 'NoneType' object has no attribute 'text' " and it fails. I wish I had a clue. It works fine locally and passes all the connection tests.

I see no choice for me but to change libraries.

d6chaub avatar Sep 08 '21 20:09 d6chaub

update - I have found the issue. @Dhyanesh97

For anyone with this issue, please print out all of your environment variables to ensure that they are declared and not 'None'.

Be cautious using getenv as this will of course return None and pass it on if your env var dict doesn't contain what you think,

The stack trace for this error is very convoluted and blames flask and wsgi and so on, but ultimately it leads to the fact that the error message for this library is not very good for the circumstance of the url provided being a Nonetype.

I am on an enterprise account and therefore not allowed to make a patch myself due to legal issues, but propose the following change to the library to make a clearer error message for this case.

in site-packages/office365/runtime/auth/providers/acs_token_provider.py - def get_app_only_access_token(self): try: realm = self._get_realm_from_target_url() url_info = urlparse(self.url) return self._get_app_only_access_token(url_info.hostname, realm) except requests.exceptions.RequestException as e: self.error = e.response.text if e.response is not None else str(e) raise ValueError(self.error)

d6chaub avatar Sep 14 '21 01:09 d6chaub

Currently facing the same issue, anyone got any possible solutions?

XhulianoPoci avatar Dec 15 '22 13:12 XhulianoPoci