JonathanHolvey / sharepy

Simple SharePoint authentication for Python
GNU General Public License v3.0
175 stars 52 forks source link

Recent 403-Forbidden when uploading files (using Files/Add) #80

Open cesarvegamx opened 8 months ago

cesarvegamx commented 8 months ago

I've been using this library for a couple of years in my organization. We use it to get and put files in sharepoint for further processing by an ETL.

Since a last week all the Files/add operation stopped to work in our three environments: dev, staging, prod. Reading files from sharepoint still works everywhere.

full_url = "https://mycompany.sharepoint.com/sites/"+p_site+"/_api/web/GetFolderByServerRelativeUrl('/sites/"+p_site+"/Shared Documents/"+p_remote_folder+"/')/Files/add(url='"+p_file_name+"',overwrite=true)"; We're getting a 403-forbidden response.

I must clarify that the account used for our connection has full permissions on the sharepoint (remember it was working, its not a new development).

I tried the same operation using postman: same url, same account, and there, I could succesfully add the file to sharepoint.

It seems like a recent change in sharepoint broke the Files/add method.

JobrJobrJobr commented 8 months ago

I think I've been having a similar issue. We have two scripts that use Sharepy to update a sharepoint table and upload data to our sharepoint site. We had never had an issue with them, until a few weeks ago, around the same time this issue was created. We don't run them very often, about once every three months, so they may have stopped working before this point.

JobrJobrJobr commented 8 months ago

I was able to sort out this issue. To fix, I opened a connection to our sharepoint site. Then sent an empty post to: https://<company_name>.sharepoint.com/sites/<site_name>/_api/contextinfo From that response, I extracted the Form Digest Value and added it to the "X-RequestDigest" header of all future posts in the automation script. The post function in sharepy takes similar steps to acquire a digest value, but it instead assigns it to the "Authorization" header.