From 852a80e00e16845bfd29207cdcad96c4ded1889a Mon Sep 17 00:00:00 2001 From: k8n Date: Mon, 30 Jun 2014 10:59:26 -0400 Subject: [PATCH 1/2] Attempt to refresh access token if expired at upload time --- box/client.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/box/client.py b/box/client.py index 3dd22c4..aa99a71 100644 --- a/box/client.py +++ b/box/client.py @@ -617,7 +617,6 @@ def upload_file(self, filename, fileobj, parent=0, content_created_at=None, cont - content_modified_at: (optional) a timestamp (datetime or a properly formatted string) of the time the content was last modified """ - try_refresh=True form = {"parent_id": self._get_id(parent)} if content_created_at: @@ -631,9 +630,12 @@ def upload_file(self, filename, fileobj, parent=0, content_created_at=None, cont form, headers=self.default_headers, files={filename: (filename, fileobj)}) - if response.status_code == UNAUTHORIZED and try_refresh and self.credentials.refresh(): - try_refresh=False - return self.upload_file(filename, fileobj) + + if response.status_code == UNAUTHORIZED and self.credentials.refresh(): + response = requests.post('https://upload.box.com/api/2.0/files/content', + form, + headers=self.default_headers, + files={filename: (filename, fileobj)}) self._check_for_errors(response) return response.json()['entries'][0] From c8dbe48704025305d397fb01b762a8fc30bc5688 Mon Sep 17 00:00:00 2001 From: k8n Date: Mon, 30 Jun 2014 11:03:53 -0400 Subject: [PATCH 2/2] Update client.py --- box/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/box/client.py b/box/client.py index aa99a71..5901638 100644 --- a/box/client.py +++ b/box/client.py @@ -632,6 +632,7 @@ def upload_file(self, filename, fileobj, parent=0, content_created_at=None, cont files={filename: (filename, fileobj)}) if response.status_code == UNAUTHORIZED and self.credentials.refresh(): + fileobj.seek(0) # rewind, just in case response = requests.post('https://upload.box.com/api/2.0/files/content', form, headers=self.default_headers,