From 1a245a48a311b1df731bc31893999040f43f7473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Gradit?= Date: Fri, 8 May 2020 16:13:30 -0400 Subject: [PATCH 1/2] Add timeout support on upload operations --- shotgun_api3/shotgun.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 3f259fd2..31ca847d 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -3976,7 +3976,10 @@ def _upload_data_to_storage(self, data, content_type, size, storage_url): request.add_header("Content-Type", content_type) request.add_header("Content-Length", size) request.get_method = lambda: "PUT" - result = opener.open(request) + if self.config.timeout_secs is not None: + result = opener.open(request, timeout=self.config.timeout_secs) + else: + result = opener.open(request) etag = result.info()["Etag"] except urllib.error.HTTPError as e: if e.code == 500: @@ -4069,7 +4072,10 @@ def _send_form(self, url, params): # Perform the request try: - resp = opener.open(url, params) + if self.config.timeout_secs is not None: + resp = opener.open(url, params, timeout=self.config.timeout_secs) + else: + resp = opener.open(url, params) result = resp.read() # response headers are in str(resp.info()).splitlines() except urllib.error.HTTPError as e: From 71d7ed9fced47360bb8a3bdf75e52fdb074df564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Gradit?= Date: Thu, 14 May 2020 11:04:10 -0400 Subject: [PATCH 2/2] Add SSLError to allow managing timeout as ShotgunError. --- shotgun_api3/shotgun.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shotgun_api3/shotgun.py b/shotgun_api3/shotgun.py index 31ca847d..e44e088d 100644 --- a/shotgun_api3/shotgun.py +++ b/shotgun_api3/shotgun.py @@ -3981,6 +3981,10 @@ def _upload_data_to_storage(self, data, content_type, size, storage_url): else: result = opener.open(request) etag = result.info()["Etag"] + + except ssl.SSLError, e: + raise ShotgunError("Unanticipated error occurred uploading to %s: %s" % (storage_url, e)) + except urllib.error.HTTPError as e: if e.code == 500: raise ShotgunError("Server encountered an internal error.\n%s\n%s\n\n" % (storage_url, e)) @@ -4078,6 +4082,10 @@ def _send_form(self, url, params): resp = opener.open(url, params) result = resp.read() # response headers are in str(resp.info()).splitlines() + + except ssl.SSLError, e: + raise ShotgunError("Unanticipated error occurred %s" % (e)) + except urllib.error.HTTPError as e: if e.code == 500: raise ShotgunError("Server encountered an internal error. "