Open ghost opened 1 year ago
@homieHolmes I am getting same error for the user credentials, is there some other secret to making things work that you figured out?
@cmosguy Beats me.
I ended up using ClientCredential because my business account has 2FA and I also cannot get app password because of permission issue. I suggest that you try what @vgrem mentioned here, Option 2 worked for me.
The problem is with authentication. In my case, I couldn't use my credentials (user and password) because of the way my company setup the access to the Sharepoint.
The solution can be found in the section "Setting up an app-only principal with tenant permissions" of https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
Once you have access to client_id and client_secret, use them to create the authentication. Please, see the example below:
from office365.sharepoint.client_context import ClientContext from office365.runtime.auth.authentication_context import AuthenticationContext
client_id="{client id}" client_secret="{client secret}" url = "https://{tenant}.sharepoint.com/sites/{site}"
ctx_auth = AuthenticationContext(url) if ctx_auth.acquire_token_for_app(client_id, client_secret): ctx = ClientContext(url, ctx_auth) web = ctx.web ctx.load(web) ctx.execute_query() print("Web title: {0}".format(web.properties['Title']))
else: print(ctx_auth.get_last_error())
and this is the error I get
My account has no 2FA. I have no idea what causes this error, perhaps I need client_credentials too? And if I need client_credentials (with client_id and client_secret), which permission do I need to grant in api permission in Azure app, Files.Read.All and Sites.Read.All ? (This is an organization sharepoint.)
Edit: I ended up using ClientCredential but face this error instead
403 Client Error: Forbidden for url: https://xxx.sharepoint.com/sites/xxx/_api/Web/getFileByServerRelativeUrl('%2Fsites%2Fxxx%2FShared%2520Documents%2FGeneral%2FWorking%2Fwork_place.xlsx