-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upload fails with <Response [403]> in sharepoint ADFS. #59
Comments
The 403 response code means that you don't have permission to access the resource you're trying to access (or create in this case). You should probably double check the path you're trying to upload to, and check with your site administrator. For more information on that status code, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 Additionally, you should check your POST request call, as it doesn't look quite right to me. You should have something like this: with open(filepath, "rb") as f:
data = f.read()
url = "https://example.sharepoint.com/GetFolderByServerRelativeUrl('{}')/Files/add(url='{}',overwrite=true)"
r = s.post(url.format(folder, filename), data=data, headers={"content-length": len(data)}) For a full example on uploading files, see #4 (comment). I've also added this to the project readme. |
@JonathanHolvey - I went through your example code but was just trying to test if upload is working fine. import sharepy
import urllib
s = sharepy.connect("xxxx.sharepoint.com", "xxxx@org.com", "password")
folder = "/Shared Documents/xxxx/xxxx/xxxx/Reports"
filename = "test.xlsx"
with open(filename, "rb") as f:
data = f.read()
url = "https://xxxx.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('{}')/Files/add(url='{}',overwrite=true)"
r = s.post(url.format(folder, filename), data=data, headers={"content-length": str(len(data))})
print (r) Above code is executed with |
Can you try replacing the space in the folder name with |
I'm still getting "<Response [404]>" even after replacing space with %20. |
Apologies, I just realised the URL in my example above was missing |
I'm back to original error "<Response [403]>". |
When I open my company sharepoint site (xxxx.sharepoint.com) in a private browser then after login to sharepoint using xxxx.org.com this is redirecting to ADFS server where I need to login using company id (xxxx) not email (like xxxx.sharepoint.com) and password then It's landing to sharepoint site. |
Are you able to access any data on the site through SharePy using a GET request? |
Same issue here. i run the code in Azure pipeline. s = sharepy.connect(sharepoint_url, username=username, password=password) here is the output i use 'GET' request method to get the with status code 200 but when i try to use "Post" request below is another pipeline has same issue. Please help!!! |
I'm wondering if this might be related to #49. Can you try adding the following header to your request? headers = {
'Authorization': f'Bearer {self.auth.digest}',
} |
@JonathanHolvey - I'm using below code which is working in my local system with 200 status (which is preauthorized to adfs server because of sso) but same is not working while running in Jenkins python container agent and throwing authentication error. url = "https://xxxx.sharepoint.com/sites/subsite/_api/web/GetFolderByServerRelativeUrl('{}')/Files/add(url='{}',overwrite=true)" Jenkins agent error: I can clearly see it's failing at adfs authentication, could you please help to add one more step for adfs authentication (with credentials) in script . |
Same issue. |
Thanks it solved when roll back the version to 1.3.0 |
This is not working for me as I've different credentials for adfs and sharepoint. |
@JonathanHolvey |
@JonathanHolvey Hello SharePy v 1.3.0 - Can do all the tasks: connect, download, upload Trying to cope with some issues arround file permisions I got the next message (v 2.0.0): Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): s_file is defined like this: os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())),'sp-session.pkl') I'm trying to force the session file, because I found out that I have multiple versions of sharepy with different users. When I downgrade to 1.3.0 I get the results I want, but download becomes messy. |
Just to tag in here, we had the same issue in our regression tests when we upgraded sharepy to 2.0.0. 1.3.0 kept on working. |
Same issue for our implementation. We've rolled back to 1.3.0 to fix. |
Hi all, I have run into the same issue with 2.0.0 but found a solution that works for me. Essentially following the example provided by @JonathanHolvey in #4 (comment) but before the POST request to upload file, make another POST request to _api/contextinfo to obtain the FormDigestValue (parse the response like r.json()["d"]["GetContextWebInformation"]["FormDigestValue"]) and update the session with this value (e.g. s.auth.digest = [FormDigestValue]. I first rolled back to 1.3.0 but could not even authenticate. So with 2.0.0 this is the only workaround for me. |
I also had the same issue roll backed to 1.3.0 and it worked |
Thank you!! That solved my issue with just a little bit of code added in. One note regarding the code from issue #4, I did have to add a '/' to the end of the url and remove the '/' from the beginning of the Destination folder to get it to work on my end. The string concatenation did not work otherwise and I got 404 errors until swapping that around. |
I'm using below lines to upload a file to subdirectory of Sharepoint online which has ADFS in background but this is never working for me to upload.
Python code:
Above code is executed with
<Response [403]>
value in 'r'.Kindly Help on this.
Thanks,
Gaurav
The text was updated successfully, but these errors were encountered: