sharepy icon indicating copy to clipboard operation
sharepy copied to clipboard

v2 Issues with POST and DELETE Calls

Open Cable-1406 opened this issue 3 years ago • 13 comments

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.

Cable-1406 avatar Jan 03 '21 10:01 Cable-1406

Can you please check that the auth cookies have been set correctly?

print(s.auth.cookie)
print(s.auth.digest)

JonathanHolvey avatar Jan 03 '21 11:01 JonathanHolvey

Well it returns something so I guess it works.

(Should I also put the output here or is there confidential information in these outputs)

Cable-1406 avatar Jan 03 '21 12:01 Cable-1406

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?

JonathanHolvey avatar Jan 03 '21 12:01 JonathanHolvey

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?

Cable-1406 avatar Jan 03 '21 13:01 Cable-1406

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.

JonathanHolvey avatar Jan 03 '21 13:01 JonathanHolvey

Okay thanks :)

Cable-1406 avatar Jan 03 '21 13:01 Cable-1406

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.

JonathanHolvey avatar Jan 04 '21 03:01 JonathanHolvey

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.

JonathanHolvey avatar Jan 04 '21 03:01 JonathanHolvey

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

JonathanHolvey avatar Jan 09 '21 01:01 JonathanHolvey

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?

BartoszCiesla avatar Mar 02 '21 17:03 BartoszCiesla

I got the same issue. Workaround with adding 'Authorization' header before post works for me:

s.headers.update({'Authorization': 'Bearer ' + s.auth.digest})

jarent avatar Apr 14 '21 05:04 jarent

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 "", line 5, in , 'Authorization': f'Bearer {s.auth.digest}'

AttributeError: 'NoneType' object has no attribute 'digest'

does the s object has this s.auth.digest ?

JhongTingDanny avatar Feb 14 '22 07:02 JhongTingDanny

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.

cesarvegamx avatar Jun 16 '22 07:06 cesarvegamx