Skip to content

Commit 666fa0c

Browse files
SG-35712 Prevent flaky disconnection when uploading thumbnails on publish (#368)
* Handle opening the connection in the retry block * Update parent * Revert parent class for `CACertsHTTPSConnection` * Remove testing argument
1 parent e4d5576 commit 666fa0c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

shotgun_api3/shotgun.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,16 +4504,16 @@ def _upload_data_to_storage(self, data, content_type, size, storage_url):
45044504
:returns: upload url.
45054505
:rtype: str
45064506
"""
4507-
opener = self._build_opener(urllib.request.HTTPHandler)
4508-
4509-
request = urllib.request.Request(storage_url, data=data)
4510-
request.add_header("Content-Type", content_type)
4511-
request.add_header("Content-Length", size)
4512-
request.get_method = lambda: "PUT"
45134507

45144508
attempt = 1
45154509
while attempt <= self.MAX_ATTEMPTS:
45164510
try:
4511+
opener = self._build_opener(urllib.request.HTTPHandler)
4512+
4513+
request = urllib.request.Request(storage_url, data=data)
4514+
request.add_header("Content-Type", content_type)
4515+
request.add_header("Content-Length", size)
4516+
request.get_method = lambda: "PUT"
45174517
result = self._make_upload_request(request, opener)
45184518

45194519
LOG.debug("Completed request to %s" % request.get_method())
@@ -4634,12 +4634,12 @@ def _send_form(self, url, params):
46344634

46354635
params.update(self._auth_params())
46364636

4637-
opener = self._build_opener(FormPostHandler)
46384637

46394638
attempt = 1
46404639
while attempt <= self.MAX_ATTEMPTS:
46414640
# Perform the request
46424641
try:
4642+
opener = self._build_opener(FormPostHandler)
46434643
resp = opener.open(url, params)
46444644
result = resp.read()
46454645
# response headers are in str(resp.info()).splitlines()
@@ -4679,11 +4679,11 @@ def __init__(self, *args, **kwargs):
46794679
"""
46804680
# Pop that argument,
46814681
self.__ca_certs = kwargs.pop("ca_certs")
4682-
http_client.HTTPConnection.__init__(self, *args, **kwargs)
4682+
super().__init__(self, *args, **kwargs)
46834683

46844684
def connect(self):
46854685
"Connect to a host on a given (SSL) port."
4686-
http_client.HTTPConnection.connect(self)
4686+
super().connect(self)
46874687
# Now that the regular HTTP socket has been created, wrap it with our SSL certs.
46884688
if six.PY38:
46894689
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
@@ -4698,13 +4698,13 @@ def connect(self):
46984698
)
46994699

47004700

4701-
class CACertsHTTPSHandler(urllib.request.HTTPSHandler):
4701+
class CACertsHTTPSHandler(urllib.request.HTTPHandler):
47024702
"""
47034703
Handler that ensures https connections are created with the custom CA certs.
47044704
"""
47054705

47064706
def __init__(self, cacerts):
4707-
urllib.request.HTTPSHandler.__init__(self)
4707+
super().__init__(self)
47084708
self.__ca_certs = cacerts
47094709

47104710
def https_open(self, req):

0 commit comments

Comments
 (0)