Skip to content

Commit 30b5830

Browse files
author
Richard O'Dwyer
committed
Adds drive_upload_item, handle lock error when file is open in web browser (excel online) and drive attempts to update it at the same time
1 parent 95d6377 commit 30b5830

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

microsoftgraph/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ def drive_get_item(self, item_id, params=None, **kwargs):
493493
url = "https://graph.microsoft.com/beta/me/drive/items/{0}".format(item_id)
494494
return self._get(url, params=params, **kwargs)
495495

496+
@token_required
497+
def drive_upload_item(self, item_id, params=None, **kwargs):
498+
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/content".format(item_id)
499+
kwargs['headers'] = {'Content-Type': 'text/plain'}
500+
return self._put(url, params=params, **kwargs)
501+
496502
# Excel
497503
@token_required
498504
def excel_get_worksheets(self, item_id, params=None, **kwargs):
@@ -658,4 +664,9 @@ def _parse(self, response):
658664
elif status_code == 509:
659665
raise exceptions.BandwidthLimitExceeded(r)
660666
else:
667+
if r['error']['innerError']['code'] == 'lockMismatch':
668+
# File is currently locked due to being open in the web browser
669+
# while attempting to reupload a new version to the drive.
670+
# Thus temporarily unavailable.
671+
raise exceptions.ServiceUnavailable(r)
661672
raise exceptions.UnknownError(r)

0 commit comments

Comments
 (0)