tencentcloud-sdk-python-common 3.0.1316__py2.py3-none-any.whl → 3.0.1318__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tencentcloud-sdk-python-common might be problematic. Click here for more details.
- tencentcloud/__init__.py +1 -1
- tencentcloud/common/abstract_client.py +37 -18
- tencentcloud/common/profile/client_profile.py +4 -3
- tencentcloud/common/retry.py +62 -0
- {tencentcloud_sdk_python_common-3.0.1316.dist-info → tencentcloud_sdk_python_common-3.0.1318.dist-info}/METADATA +1 -1
- {tencentcloud_sdk_python_common-3.0.1316.dist-info → tencentcloud_sdk_python_common-3.0.1318.dist-info}/RECORD +8 -7
- {tencentcloud_sdk_python_common-3.0.1316.dist-info → tencentcloud_sdk_python_common-3.0.1318.dist-info}/WHEEL +0 -0
- {tencentcloud_sdk_python_common-3.0.1316.dist-info → tencentcloud_sdk_python_common-3.0.1318.dist-info}/top_level.txt +0 -0
tencentcloud/__init__.py
CHANGED
|
@@ -39,6 +39,7 @@ from tencentcloud.common.http.request import RequestInternal
|
|
|
39
39
|
from tencentcloud.common.profile.client_profile import ClientProfile, RegionBreakerProfile
|
|
40
40
|
from tencentcloud.common.sign import Sign
|
|
41
41
|
from tencentcloud.common.circuit_breaker import CircuitBreaker
|
|
42
|
+
from tencentcloud.common.retry import NoopRetryer
|
|
42
43
|
|
|
43
44
|
warnings.filterwarnings("ignore", module="tencentcloud", category=UserWarning)
|
|
44
45
|
|
|
@@ -428,11 +429,16 @@ class AbstractClient(object):
|
|
|
428
429
|
return self.request.send_request(req)
|
|
429
430
|
|
|
430
431
|
def call(self, action, params, options=None, headers=None):
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
432
|
+
|
|
433
|
+
def _call_once():
|
|
434
|
+
resp = self._call(action, params, options, headers)
|
|
435
|
+
self._check_status(resp)
|
|
436
|
+
self._check_error(resp)
|
|
437
|
+
logger.debug("GetResponse: %s", ResponsePrettyFormatter(resp))
|
|
438
|
+
return resp
|
|
439
|
+
|
|
440
|
+
retryer = self.profile.retryer or NoopRetryer()
|
|
441
|
+
return retryer.send_request(_call_once).content
|
|
436
442
|
|
|
437
443
|
def _call_with_region_breaker(self, action, params, options=None, headers=None):
|
|
438
444
|
endpoint = self._get_endpoint()
|
|
@@ -508,23 +514,36 @@ class AbstractClient(object):
|
|
|
508
514
|
:type options: dict
|
|
509
515
|
:param options: request options, like {"SkipSign": False, "IsMultipart": False, "IsOctetStream": False, "BinaryParams": []}
|
|
510
516
|
"""
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
517
|
+
|
|
518
|
+
def _call_once():
|
|
519
|
+
resp = self._call(action, params, options, headers)
|
|
520
|
+
self._check_status(resp)
|
|
521
|
+
self._check_error(resp)
|
|
522
|
+
logger.debug("GetResponse: %s", ResponsePrettyFormatter(resp))
|
|
523
|
+
return resp
|
|
524
|
+
|
|
525
|
+
retryer = self.profile.retryer or NoopRetryer()
|
|
526
|
+
return json.loads(retryer.send_request(_call_once).content)
|
|
516
527
|
|
|
517
528
|
def call_sse(self, action, params, headers=None, options=None):
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
529
|
+
def _call_once():
|
|
530
|
+
resp = self._call(action, params, options, headers)
|
|
531
|
+
self._check_status(resp)
|
|
532
|
+
self._check_error(resp)
|
|
533
|
+
return resp
|
|
534
|
+
|
|
535
|
+
retryer = self.profile.retryer or NoopRetryer()
|
|
536
|
+
return self._process_response_sse(retryer.send_request(_call_once))
|
|
522
537
|
|
|
523
538
|
def _call_and_deserialize(self, action, params, resp_type, headers=None, options=None):
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
539
|
+
def _call_once():
|
|
540
|
+
resp = self._call(action, params, options, headers)
|
|
541
|
+
self._check_status(resp)
|
|
542
|
+
self._check_error(resp)
|
|
543
|
+
return resp
|
|
544
|
+
|
|
545
|
+
retryer = self.profile.retryer or NoopRetryer()
|
|
546
|
+
return self._process_response(retryer.send_request(_call_once), resp_type)
|
|
528
547
|
|
|
529
548
|
def _process_response(self, resp, resp_type):
|
|
530
549
|
if resp.headers.get('Content-Type') == "text/event-stream":
|
|
@@ -21,7 +21,7 @@ class ClientProfile(object):
|
|
|
21
21
|
unsignedPayload = False
|
|
22
22
|
|
|
23
23
|
def __init__(self, signMethod=None, httpProfile=None, language="zh-CN",
|
|
24
|
-
disable_region_breaker=True, region_breaker_profile=None, request_client=None):
|
|
24
|
+
disable_region_breaker=True, region_breaker_profile=None, request_client=None, retryer=None):
|
|
25
25
|
"""SDK profile.
|
|
26
26
|
|
|
27
27
|
:param signMethod: The signature method, valid choice: HmacSHA1, HmacSHA256, TC3-HMAC-SHA256
|
|
@@ -55,13 +55,15 @@ class ClientProfile(object):
|
|
|
55
55
|
elif request_client is not None:
|
|
56
56
|
warnings.warn("RequestClient not match the regexp: ^[0-9a-zA-Z-_,;.]+$, ignored")
|
|
57
57
|
|
|
58
|
+
self.retryer = retryer
|
|
59
|
+
|
|
58
60
|
|
|
59
61
|
class RegionBreakerProfile(object):
|
|
60
62
|
|
|
61
63
|
def __init__(self, backup_endpoint="ap-guangzhou.tencentcloudapi.com",
|
|
62
64
|
max_fail_num=5,
|
|
63
65
|
max_fail_percent=0.75,
|
|
64
|
-
window_interval=60*5,
|
|
66
|
+
window_interval=60 * 5,
|
|
65
67
|
timeout=60,
|
|
66
68
|
max_requests=5):
|
|
67
69
|
"""RegionBreaker profile.
|
|
@@ -102,4 +104,3 @@ class RegionBreakerProfile(object):
|
|
|
102
104
|
if len(region.split("-")) != 2:
|
|
103
105
|
return False
|
|
104
106
|
return True
|
|
105
|
-
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
from tencentcloud.common.exception import TencentCloudSDKException
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NoopRetryer(object):
|
|
8
|
+
def send_request(self, fn):
|
|
9
|
+
return fn()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StandardRetryer(object):
|
|
13
|
+
def __init__(self, max_attempts=3, backoff_fn=None, logger=None):
|
|
14
|
+
self._max_attempts = max_attempts
|
|
15
|
+
self._backoff_fn = backoff_fn or self.backoff
|
|
16
|
+
self._logger = logger
|
|
17
|
+
|
|
18
|
+
def send_request(self, fn):
|
|
19
|
+
resp = None
|
|
20
|
+
err = None
|
|
21
|
+
|
|
22
|
+
for n in range(self._max_attempts):
|
|
23
|
+
try:
|
|
24
|
+
resp = fn()
|
|
25
|
+
except TencentCloudSDKException as e:
|
|
26
|
+
err = e
|
|
27
|
+
|
|
28
|
+
if not self.should_retry(resp, err):
|
|
29
|
+
if err:
|
|
30
|
+
raise err
|
|
31
|
+
return resp
|
|
32
|
+
|
|
33
|
+
sleep = self._backoff_fn(n)
|
|
34
|
+
self.on_retry(n, sleep, resp, err)
|
|
35
|
+
time.sleep(sleep)
|
|
36
|
+
|
|
37
|
+
raise err
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def should_retry(resp, err):
|
|
41
|
+
if not err:
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
if not isinstance(err, TencentCloudSDKException):
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
ec = err.get_code()
|
|
48
|
+
if ec in (
|
|
49
|
+
"ClientNetworkError", "ServerNetworkError", "RequestLimitExceeded",
|
|
50
|
+
"RequestLimitExceeded.UinLimitExceeded", "RequestLimitExceeded.GlobalRegionUinLimitExceeded"
|
|
51
|
+
):
|
|
52
|
+
return True
|
|
53
|
+
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def backoff(n):
|
|
58
|
+
return 2 ** n
|
|
59
|
+
|
|
60
|
+
def on_retry(self, n, sleep, resp, err):
|
|
61
|
+
if self._logger:
|
|
62
|
+
self._logger.debug("retry: n=%d sleep=%ss err=%s", n, sleep, err)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
tencentcloud/__init__.py,sha256=
|
|
1
|
+
tencentcloud/__init__.py,sha256=ZhQ3BnWy9ymylcbIEjTpD8U2MF1gogRWinR50bHTm40,631
|
|
2
2
|
tencentcloud/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
tencentcloud/common/abstract_client.py,sha256=
|
|
3
|
+
tencentcloud/common/abstract_client.py,sha256=f1sZd_itBqi2m_59hBEWtX_V7EDf1s9EUXPWBIfL-HA,24457
|
|
4
4
|
tencentcloud/common/abstract_model.py,sha256=3v71msaz-M3krVA5iSiq8WgIOorPbHgs5Y63TPLBJvo,2335
|
|
5
5
|
tencentcloud/common/circuit_breaker.py,sha256=p_6ssklMRtR-YKNGcFLd3ClUvZPs8ZLnVkhjcOZA0DY,4301
|
|
6
6
|
tencentcloud/common/common_client.py,sha256=H8VH-6y41AN1aIjz4PaJCpj-T1EoW9KGfaeqxPEBzWg,1958
|
|
7
7
|
tencentcloud/common/credential.py,sha256=Sjq5XfoN28OZeMmB05JWSwCS4w3z1CR5TW0PN9HY80k,16447
|
|
8
|
+
tencentcloud/common/retry.py,sha256=ZrusVQ6eQITlNQoFisH250NWdSbuoQpU69H15igQOjg,1599
|
|
8
9
|
tencentcloud/common/sign.py,sha256=Mm51G6huhhT91yayB-KKWCQFIuy59dFzdSwolNfSuwM,1568
|
|
9
10
|
tencentcloud/common/exception/__init__.py,sha256=xK4vqaAlCWY5pGTDaz21vzIO6izEBESCNDeBNvojqYo,735
|
|
10
11
|
tencentcloud/common/exception/tencent_cloud_sdk_exception.py,sha256=y6DuJBE1T81um8MUs4__hZWrwzSRU28XQHU7GqlYm1w,760
|
|
@@ -12,9 +13,9 @@ tencentcloud/common/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
|
12
13
|
tencentcloud/common/http/pre_conn.py,sha256=aeEqmTc2JKO8Wd6r_SwLofCyrfPv-A0hQV00SZAgpU0,2488
|
|
13
14
|
tencentcloud/common/http/request.py,sha256=Qgo3BI4cbbEv1Y2EvlB8KQSh1brvPKRypSdfnY_Yay0,5642
|
|
14
15
|
tencentcloud/common/profile/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
tencentcloud/common/profile/client_profile.py,sha256=
|
|
16
|
+
tencentcloud/common/profile/client_profile.py,sha256=9CaCh5gApAGlf9DEausaqekYMps_yDs4pDbtXk3twPo,5207
|
|
16
17
|
tencentcloud/common/profile/http_profile.py,sha256=cASJQE1eCTM3t5miwrGxMNMDMBGq0RG0Nfmdxk8liUw,1930
|
|
17
|
-
tencentcloud_sdk_python_common-3.0.
|
|
18
|
-
tencentcloud_sdk_python_common-3.0.
|
|
19
|
-
tencentcloud_sdk_python_common-3.0.
|
|
20
|
-
tencentcloud_sdk_python_common-3.0.
|
|
18
|
+
tencentcloud_sdk_python_common-3.0.1318.dist-info/METADATA,sha256=ztejsyjE5iUwQ5Ir-4Y27G9dkO3OzjzrPzBCHNlwKuw,1487
|
|
19
|
+
tencentcloud_sdk_python_common-3.0.1318.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
|
|
20
|
+
tencentcloud_sdk_python_common-3.0.1318.dist-info/top_level.txt,sha256=g-8OyzoqI6O6LiS85zkeNzhB-osEnRIPZMdyRd_0eL0,13
|
|
21
|
+
tencentcloud_sdk_python_common-3.0.1318.dist-info/RECORD,,
|
|
File without changes
|