Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
Unauthorized for URL
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'])
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>