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

403 when using moveto/copyto and UserCredential

Open protis-pennington opened this issue 3 years ago • 4 comments

I keep getting a 403 error when trying to move a file to another directory within sharepoint:

url = "https://<tenant>.sharepoint.com/sites/Bench/Shared Documents/General/A/test_file.xlsx"

File\
    .from_url(url)\
    .with_credentials(UserCredential(user_name=<username>, password=<password>))\
    .moveto("/sites/Bench/Shared Documents/General/B/test_file.xlsx", 1)\
    .execute_query()

gets me:

requests.exceptions.HTTPError: 403 Client Error: FORBIDDEN for url: https://<tenant>.sharepoint.com/sites/Bench/_api/Web/getFileByServerRelativeUrl('%2Fsites%2FBench%2FShared%2520Documents%2FGeneral%2FA%2Ftest_file.xlsx')/moveto(newurl='%2Fsites%2FBench%2FShared%20Documents%2FGeneral%2FB%2Ftest_file.xlsx',flags=1)

i should have permission to access this directory and downloading files works using

File\
    .from_url(url)\
    .with_credentials(UserCredential(user_name=<username>, password=<password>))\
    .download(local_file)\
    .execute_query()

am i missing something obvious? not familiar with sharepoint...

versions:

Python 3.9.10
Office365-REST-Python-Client 2.3.10

logfile:

2022-01-31T14:26:32-0600 DEBUG    [office365.runtime.auth.providers.saml_token_provider.SamlTokenProvider.ensure_authentication_cookie] get_authentication_cookie called
2022-01-31T14:26:32-0600 DEBUG    [office365.runtime.auth.providers.saml_token_provider.SamlTokenProvider.ensure_authentication_cookie] Acquiring Access Token..
2022-01-31T14:26:32-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): login.microsoftonline.com:443
2022-01-31T14:26:32-0600 DEBUG    [urllib3.connectionpool] https://login.microsoftonline.com:443 "POST /GetUserRealm.srf HTTP/1.1" 200 240
2022-01-31T14:26:32-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): login.microsoftonline.com:443
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] https://login.microsoftonline.com:443 "POST /extSTS.srf HTTP/1.1" 200 3508
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): <tenant>.sharepoint.com:443
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] https://<tenant>.sharepoint.com:443 "POST /_forms/default.aspx?wa=wsignin1.0 HTTP/1.1" 302 118
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] https://<tenant>.sharepoint.com:443 "GET / HTTP/1.1" 403 13
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): <tenant>.sharepoint.com:443
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] https://<tenant>.sharepoint.com:443 "POST /_api/contextInfo HTTP/1.1" 200 None
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): <tenant>.sharepoint.com:443
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] https://<tenant>.sharepoint.com:443 "POST /_api/SP.Web.GetWebUrlFromPageUrl HTTP/1.1" 200 None
2022-01-31T14:26:33-0600 DEBUG    [urllib3.connectionpool] Starting new HTTPS connection (1): <tenant>.sharepoint.com:443
2022-01-31T14:26:34-0600 DEBUG    [urllib3.connectionpool] https://<tenant>.sharepoint.com:443 "POST /sites/Bench/_api/Web/getFileByServerRelativeUrl('%2Fsites%2FBench%2FShared%2520Documents%2FGeneral%2FA%2Ftest_file.xlsx')/moveto(newurl='%2Fsites%2FBench%2FShared%20Documents%2FGeneral%2FB%2Ftest_file.xlsx',flags=1) HTTP/1.1" 403 None

protis-pennington avatar Jan 31 '22 21:01 protis-pennington

Are there any updates on this issue? I am currently running into the same problem.

KevinHepster avatar May 11 '22 08:05 KevinHepster

i have same issue, have you found a soultion?

balajeek avatar May 25 '22 17:05 balajeek

Same here, i have the same problem, any updates?

josefernandeztrebol avatar Mar 24 '23 12:03 josefernandeztrebol

I've never been able to get UserCredential to work: credentials=UserCredential(sharepoint_user,sharepoint_password) Traceback (most recent call last):

File "[file].py", line 1, in <module> credentials=UserCredential(sharepoint_user,sharepoint_password)

NameError: name 'UserCredential' is not defined

The following does seem to work for me: ClientContext(url).with_user_credentials(sharepoint_user,sharepoint_password)

yuorfaec avatar Sep 08 '23 21:09 yuorfaec