sharepy
sharepy copied to clipboard
v2 Issues with POST and DELETE Calls
Hey Jonathan, thanks for the quick replies so far.
As suggested in the last Issue (https://github.com/JonathanHolvey/sharepy/issues/47) I freshly downloaded the beta v2.0.0 Branch and tried running a small test script which creates a new Folder (POST), gets some information of it (GET) and finally deletes the folder (DELETE).
from Local import sharepy as sharepy
s = sharepy.connect(server_url, username=user, password=passwd)
uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/folders/add('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.post(uri)
uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/GetFolderByServerRelativeUrl('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.get(uri)
r = s.delete(uri)
The new version changed which errors I get as a response from the API: POST Error Message:
{
"error": {
"code": "-2130575251, System.Runtime.InteropServices.COMException",
"message": {
"lang": "de-DE",
"value": "Die Sicherheits\u00fcberpr\u00fcfung f\u00fcr diese Seite ist ung\u00fcltig. Klicken Sie auf die Schaltfl\u00e4che 'Zur\u00fcck' Ihres Browsers, aktualisieren Sie dann die Seite, und starten Sie den Vorgang erneut."
}
}
}
value -> The Security check for this site is invalid... and so on
GET Error Message -> just the usual IOException because of the missing folder (works if I manually create the folder)
DELETE Error Message (after manually creating the folder):
{
"error": {
"code": "-2130575251, System.Runtime.InteropServices.COMException",
"message": {
"lang": "de-DE",
"value": "Die Sicherheits\u00fcberpr\u00fcfung f\u00fcr diese Seite ist ung\u00fcltig. Klicken Sie auf die Schaltfl\u00e4che 'Zur\u00fcck' Ihres Browsers, aktualisieren Sie dann die Seite, und starten Sie den Vorgang erneut."
}
}
}
value -> The Security check for this site is invalid... and so on
The Authentication type is SharepointOnline from what I understood.
Can you please check that the auth cookies have been set correctly?
print(s.auth.cookie)
print(s.auth.digest)
Well it returns something so I guess it works.
(Should I also put the output here or is there confidential information in these outputs)
No need to post them. So long as they're both not None
it should work.
I just tried your steps on my test account, and all there requests (POST, GET, DELETE) returned 200. The test folder was created and deleted successfully. The only difference was that I used the Shared Documents library in the root site, rather than a subsite.
Are you able to test with a library in the top-level site?
Sadly I am not as I only have my Sub-Site for testing purposes.
I tried using your old approach (so the v1 one where you had an explicit post() function) and basically copied the post function and replaced it with delete. That worked out just fine. Am I allowed to use that modified approach until I can get the beta version working for me?
The only other thing I can suggest right now is to try the PyPI version of the beta package:
pip install --pre sharepy
There shouldn't be any differences between that and what you have, but it's worth checking.
I'll create a subsite myself tomorrow and see what I get.
Okay thanks :)
I just tested with a subsite, and using the URLs you provided, got a load of 404 responses. Only if I removed /sites
from the URL and folder path would the requests succeed. This is weird, as I've used /sites
in the past without issue.
I didn't get the security message you're seeing.
I've realised the name of the digest header is different in SharePy v2. Please can you try adding the following to the header dictionary in the __call__
method of auth/base.py
?
'Authorization': 'Bearer ' + self.digest
Perhaps the other header isn't supported by your site for some reason.
I've created a branch with that change for you to try. You can find it here https://github.com/JonathanHolvey/sharepy/tree/issue-%2349
I've been facing same isssue while uploading files using PUT and with change on issue-#49 branch upload works. Could you include that in next release?
I got the same issue. Workaround with adding 'Authorization' header before post works for me:
s.headers.update({'Authorization': 'Bearer ' + s.auth.digest})
s = sharepy.connect(sharepoint_url, username=username, password=password) update = s.post(url=f"https://XXXXX.sharepoint.com/sites/OceanFreightCrisis/_api/web/lists/GetByTitle('{sharepoint_list_name}')/items({id})", data=json_object,headers={'X-HTTP-Method':'MERGE', 'If-Match':'*','User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
, 'Authorization': f'Bearer {s.auth.digest}'
})
-----------------below is the output------------------------------
Requesting security token...Requesting access cookie... Authentication successful
Traceback (most recent call last):
File "
AttributeError: 'NoneType' object has no attribute 'digest'
does the s object has this s.auth.digest ?
Hi, The error "AttributeError: 'NoneType' object has no attribute 'digest'" has been fixed on Sharepy 2.0.0? I'm getting it on sharepy 1.3.