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

Unauthorized for URL

Open luigidevelopment opened this issue 4 years ago • 1 comments

Hi! I'm trying to do a simple connection, but every time I received Unauthorized error. I've created new app using Granting access using SharePoint App-Only procedures, but nothing happen.

My code is:

from office365.runtime.auth.client_credential import ClientCredential
from office365.sharepoint.client_context import ClientContext

client_id = 'client-id'
client_secret = 'client-secret'


client_credentials = ClientCredential(client_id, client_secret)

ctx = ClientContext('https://mydomain.sharepoint.com/').with_credentials(client_credentials)
web = ctx.web
ctx.load(web)
ctx.execute_query()

print(web.properties['Url'])

luigidevelopment avatar Aug 18 '21 20:08 luigidevelopment

Greetings,

are you positive the permissions have been granted per app principal (step 2)?

Refer Setting up an app-only principal with tenant permissions step for a more details.

Note: to read resources, at least Read permission needs to be granted:

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read" />
</AppPermissionRequests>

vgrem avatar Sep 07 '21 08:09 vgrem