telesign 2.3.0__py2.py3-none-any.whl → 2.3.1__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.
- telesign/rest.py +25 -2
- {telesign-2.3.0.dist-info → telesign-2.3.1.dist-info}/METADATA +1 -1
- {telesign-2.3.0.dist-info → telesign-2.3.1.dist-info}/RECORD +6 -6
- {telesign-2.3.0.dist-info → telesign-2.3.1.dist-info}/LICENSE.txt +0 -0
- {telesign-2.3.0.dist-info → telesign-2.3.1.dist-info}/WHEEL +0 -0
- {telesign-2.3.0.dist-info → telesign-2.3.1.dist-info}/top_level.txt +0 -0
telesign/rest.py
CHANGED
|
@@ -6,6 +6,7 @@ from base64 import b64encode, b64decode
|
|
|
6
6
|
from email.utils import formatdate
|
|
7
7
|
from hashlib import sha256
|
|
8
8
|
from platform import python_version
|
|
9
|
+
import time
|
|
9
10
|
|
|
10
11
|
import requests
|
|
11
12
|
import json
|
|
@@ -52,7 +53,8 @@ class RestClient(requests.models.RequestEncodingMixin):
|
|
|
52
53
|
sdk_version_dependency=None,
|
|
53
54
|
proxies=None,
|
|
54
55
|
timeout=10,
|
|
55
|
-
auth_method=None
|
|
56
|
+
auth_method=None,
|
|
57
|
+
pool_recycle=480):
|
|
56
58
|
"""
|
|
57
59
|
Telesign RestClient useful for making generic RESTful requests against our API.
|
|
58
60
|
|
|
@@ -62,13 +64,22 @@ class RestClient(requests.models.RequestEncodingMixin):
|
|
|
62
64
|
:param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
|
|
63
65
|
:param timeout: (optional) How long to wait for the server to send data before giving up, as a float,
|
|
64
66
|
or as a (connect timeout, read timeout) tuple
|
|
67
|
+
:param pool_recycle: (optional) Time in seconds to recycle the HTTP session to avoid stale connections (default 480).
|
|
68
|
+
If a session is older than this value, it will be closed and a new session will be created automatically before each request.
|
|
69
|
+
This helps prevent errors due to HTTP keep-alive connections being closed by the server after inactivity.
|
|
70
|
+
|
|
71
|
+
HTTP Keep-Alive behavior:
|
|
72
|
+
TeleSign endpoints close idle HTTP keep-alive connections after 499 seconds. If you attempt to reuse a connection older than this, you may get a 'connection reset by peer' error.
|
|
73
|
+
By default, pool_recycle=480 ensures sessions are refreshed before this limit.
|
|
65
74
|
"""
|
|
66
75
|
self.customer_id = customer_id
|
|
67
76
|
self.api_key = api_key
|
|
68
77
|
|
|
69
78
|
self.api_host = rest_endpoint
|
|
70
79
|
|
|
71
|
-
self.
|
|
80
|
+
self.pool_recycle = pool_recycle
|
|
81
|
+
self._session_created_at = None
|
|
82
|
+
self.session = self._create_session()
|
|
72
83
|
|
|
73
84
|
self.session.proxies = proxies if proxies else {}
|
|
74
85
|
|
|
@@ -234,6 +245,17 @@ class RestClient(requests.models.RequestEncodingMixin):
|
|
|
234
245
|
"""
|
|
235
246
|
return self._execute(self.session.patch, 'PATCH', resource, body, json_fields, **query_params)
|
|
236
247
|
|
|
248
|
+
def _create_session(self):
|
|
249
|
+
session = requests.Session()
|
|
250
|
+
self._session_created_at = time.time()
|
|
251
|
+
return session
|
|
252
|
+
|
|
253
|
+
def _ensure_session(self):
|
|
254
|
+
if self._session_created_at is None or (time.time() - self._session_created_at > self.pool_recycle):
|
|
255
|
+
if self.session:
|
|
256
|
+
self.session.close()
|
|
257
|
+
self.session = self._create_session()
|
|
258
|
+
|
|
237
259
|
def _execute(self, method_function, method_name, resource, body=None, json_fields=None, **query_params):
|
|
238
260
|
"""
|
|
239
261
|
Generic Telesign REST API request handler.
|
|
@@ -245,6 +267,7 @@ class RestClient(requests.models.RequestEncodingMixin):
|
|
|
245
267
|
:param query_params: query_params to perform the HTTP request with, as a dictionary.
|
|
246
268
|
:return: The RestClient Response object.
|
|
247
269
|
"""
|
|
270
|
+
self._ensure_session()
|
|
248
271
|
resource_uri = "{api_host}{resource}".format(api_host=self.api_host, resource=resource)
|
|
249
272
|
|
|
250
273
|
url_encoded_fields = self._encode_params(query_params)
|
|
@@ -3,12 +3,12 @@ telesign/appverify.py,sha256=wBeaeUxGmYcZkrbxkkXlG3-0oZr5sVvegzVpdvaoO2A,1195
|
|
|
3
3
|
telesign/intelligence.py,sha256=t-xwlgxkXw1OMupF5K4_UKWeTArOr9XPvddmqgZftPI,1452
|
|
4
4
|
telesign/messaging.py,sha256=v7l-eKUPqz7Nrwka0YNPMkC2TaoFUvQm3yp_djuTPu0,1367
|
|
5
5
|
telesign/phoneid.py,sha256=mk03NxL3wlaXpd8b-BB6q_SKfCxbtuTO19ayAHxmzz0,954
|
|
6
|
-
telesign/rest.py,sha256=
|
|
6
|
+
telesign/rest.py,sha256=AHNDyVZLa1vm2RWD4TSxr6uM4K50eH29C2Kjr3eCq8c,13911
|
|
7
7
|
telesign/score.py,sha256=Kceu6IrirN9SsuT1geEWs0QHAn6H9ZNFyIDVHcBJdwg,908
|
|
8
8
|
telesign/util.py,sha256=stDxpL5ZQeGskE_OSGP04UFHs3ZP2ACaRpW1WyQGMHg,1624
|
|
9
9
|
telesign/voice.py,sha256=DJaWyQpun-T7LfNjpxpsUjupiv2ShW1jqoFQA-CE2-Y,1341
|
|
10
|
-
telesign-2.3.
|
|
11
|
-
telesign-2.3.
|
|
12
|
-
telesign-2.3.
|
|
13
|
-
telesign-2.3.
|
|
14
|
-
telesign-2.3.
|
|
10
|
+
telesign-2.3.1.dist-info/LICENSE.txt,sha256=a--xZ4PCKUL5rpct8RrUC6ODU_8ZKIU51kJPfsA4HUs,1058
|
|
11
|
+
telesign-2.3.1.dist-info/METADATA,sha256=n3TqPKDa2uPs5_RJhzRxJVhYoiMATdENw7xPPzxz5ms,4532
|
|
12
|
+
telesign-2.3.1.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
|
|
13
|
+
telesign-2.3.1.dist-info/top_level.txt,sha256=6LG7Jcr1jnpVhOWaIShoTdwYJn0QCfPhfudyVJNz1qg,9
|
|
14
|
+
telesign-2.3.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|