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

unable to get auth token when only having access to a particular Sharepoint site

Open phoawb opened this issue 4 years ago • 2 comments

Hello, I am trying to get data from a site at abc company. I was granted full access to

https://abc.sharepoint.com/sites/relevantSite/SitePages/relevantPage.aspx

but not to the root

https://abc.sharepoint.com

I tried authenticating using the following code:

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

username = "username"
password = "password" 
site_url = "https://abc.sharepoint.com/sites/relevantSite"

ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Web title: {0}".format(web.properties['Title']))

But I just got the following error:

ValueError: Acquire token failed: An error occurred while retrieving auth cookies from https://abc.sharepoint.com/_forms/default.aspx?wa=wsignin1.0

Is there a way to make it authorise against the site that I have access to instead of the root?

phoawb avatar Dec 07 '21 16:12 phoawb

were u able to resolve this For this U need to create Client ID and clinet secret using sharapoint app only https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs#setting-up-an-app-only-principal-with-tenant-permissions

Dskpupper avatar Jan 11 '22 22:01 Dskpupper

having this same issue. the link provide is for older acl, not azure cloud.

dss010101 avatar Apr 27 '23 19:04 dss010101