python-o365
python-o365 copied to clipboard
Check_status of copied DriveItem not working as intended
I want to modify a copied DriveItem like so:
copy = calculators.copy(folder)
for status, perc_complete in copy.check_status():
print(status, perc_complete)
item = copy.get_item()
However, the check_status() method seems to fail on me, returning the following:
Client Error: 401 Client Error: Unauthorized for url: https://my_domain.sharepoint.com/_api/v2.0/drives/{drive_id}/items/item_id}) | Error Message: Invalid audience Uri 'https://graph.microsoft.com/'.
This Error arises as a requests.exceptions.HTTPError when running CopyOperation._request_status()
. I highlighted the line below. It seems as the monitor_url
breaks when the copy is complete, whilst not properly finishing the _request_status()
method. I tried catching the error around the relevant line, but can't find a good way to get the driveItem in the form of https://graph.microsoft.com/beta/drive/{drive_id}/items/{item_id}
. Any ideas to solve this issue?
def _request_status(self):
""" Checks the api endpoint to check if the async job progress """
if self.item_id:
return True
response = self.con.get(self.monitor_url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if not response:
return False
data = response.json()
self.status = data.get('status', 'inProgress')
self.completion_percentage = data.get(self._cc('percentageComplete'),
0)
self.item_id = data.get(self._cc('resourceId'), None)
return self.item_id is not None
I don't have a clue right now... sorry
Hi @alejcas @jeroenvermunt ,
I encountered this issue yesterday and after some debugging I found the following issues:
- The monitor url request is being sent using an OAuthSession object however in the documentation here no auth is actually required for the monitor url. In fact the auth headers seem to cause this to fail. I ran a test by replacing the
CopyOperation.con.session
attribute with aCopyOperation.con.get_naive_session()
object and this resolved the issue. Resolution seems to be to use a naive session for the monitor request. - The call to
get_item
method fails after patching the above because when theCopyOperation
is initialized here the parent is passed asself.drive
but should actually betarget.drive
for the logic inget_item
to work. Not sure what the best resolution to this is, maybe to create new attributes on the CopyOperation calledsource_drive
andtarget_drive
to make this clearer and parent can stay as thesource_drive
?
Happy to put a PR (or two) in for these issues in the next week or so
Hi! @will-byrne-cardano thanks for your effort!
I've merged PR #1031, Can you make another one to fix 2). I think having source_drive and target_drive it's perfect.
Thanks!
@alejcas - PR is supplied here https://github.com/O365/python-o365/pull/1033/files. Forgot to mention this issue on the PR summary but have updated now
thanks!