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

401 Client Error: Unauthorised for url on site property update

Open andrewhn opened this issue 3 years ago • 2 comments

Hello,

Thanks very much for your work on this library. I am using Office365-REST-Python-Client==2.4.4.

I have an issue which may be related to #480. I'm trying to disable sharing capability on a particular site.

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.sharing_capabilities import SharingCapabilities

admin_client = ClientContext("https://[tenant]-admin.sharepoint.com").with_client_certificate("[tenant].onmicrosoft.com", **cert_settings)
site_props = admin_client.tenant.get_site_properties_by_url("https://[tenant].sharepoint.com/sites/[site]", True).execute_query()
site_props.sharing_capability = SharingCapabilities.Disabled
## or alternatively
#site_props.set_property("SharingCapability", SharingCapabilities.Disabled)
site_props.update().execute_query()

Authentication works fine with client certificate and I'm able to see the site settings. It appears the issue is with the call to update() and then execute_query().

The error that I get is:

office365.runtime.client_request_exception.ClientRequestException: (None, None, '401 Client Error: Unauthorized for url: https://[tenant].sharepoint.com/sites/[site]/_api/Site')

I also tried with version 2.3.11, and get a similar (slightly different URL) error:

office365.runtime.client_request_exception.ClientRequestException: (None, None, '401 Client Error: Unauthorized for url: https://[tenant].sharepoint.com/sites/[site]/_api/Site?$select=Id')

I'm able to make this change using powershell with the same credentials, so I don't think it's a permissions issue.

Set-PnPTenantSite -Identity "https://[tenant].sharepoint.com/sites/[site]" -SharingCapability Disabled

Am I doing something dumb?

Thanks

andrewhn avatar Sep 13 '23 01:09 andrewhn

Hello,

thank you for catching it and providing the detailed report, the next version 2.5.3 is expected to address this issue.

Meanwhile the latest version from github could be utilized:

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

vgrem avatar Nov 05 '23 20:11 vgrem

2.5.3 version has been releaded which addresses this issue.

vgrem avatar Dec 06 '23 21:12 vgrem