@@ -48,10 +48,11 @@ class OpenTok(object):
48
48
TOKEN_SENTINEL = 'T1=='
49
49
"""For internal use."""
50
50
51
- def __init__ (self , api_key , api_secret , api_url = 'https://api.opentok.com' ):
51
+ def __init__ (self , api_key , api_secret , api_url = 'https://api.opentok.com' , timeout = None ):
52
52
self .api_key = str (api_key )
53
53
self .api_secret = api_secret
54
54
self .api_url = api_url
55
+ self .timeout = timeout
55
56
56
57
def generate_token (self , session_id , role = Roles .publisher , expire_time = None , data = None ):
57
58
"""
@@ -216,7 +217,7 @@ def create_session(self, location=None, media_mode=MediaModes.relayed):
216
217
options [u ('location' )] = location
217
218
218
219
try :
219
- response = requests .post (self .session_url (), data = options , headers = self .headers ())
220
+ response = requests .post (self .session_url (), data = options , headers = self .headers (), timeout = self . timeout )
220
221
response .encoding = 'utf-8'
221
222
222
223
if response .status_code == 403 :
@@ -284,7 +285,7 @@ def start_archive(self, session_id, **kwargs):
284
285
"""
285
286
payload = {'name' : kwargs .get ('name' ), 'sessionId' : session_id }
286
287
287
- response = requests .post (self .archive_url (), data = json .dumps (payload ), headers = self .archive_headers ())
288
+ response = requests .post (self .archive_url (), data = json .dumps (payload ), headers = self .archive_headers (), timeout = self . timeout )
288
289
289
290
if response .status_code < 300 :
290
291
return Archive (self , response .json ())
@@ -310,7 +311,7 @@ def stop_archive(self, archive_id):
310
311
311
312
:rtype: The Archive object corresponding to the archive being stopped.
312
313
"""
313
- response = requests .post (self .archive_url (archive_id ) + '/stop' , headers = self .archive_headers ())
314
+ response = requests .post (self .archive_url (archive_id ) + '/stop' , headers = self .archive_headers (), timeout = self . timeout )
314
315
315
316
if response .status_code < 300 :
316
317
return Archive (self , response .json ())
@@ -333,7 +334,7 @@ def delete_archive(self, archive_id):
333
334
334
335
:param String archive_id: The archive ID of the archive to be deleted.
335
336
"""
336
- response = requests .delete (self .archive_url (archive_id ), headers = self .archive_headers ())
337
+ response = requests .delete (self .archive_url (archive_id ), headers = self .archive_headers (), timeout = self . timeout )
337
338
338
339
if response .status_code < 300 :
339
340
pass
@@ -351,7 +352,7 @@ def get_archive(self, archive_id):
351
352
352
353
:rtype: The Archive object.
353
354
"""
354
- response = requests .get (self .archive_url (archive_id ), headers = self .archive_headers ())
355
+ response = requests .get (self .archive_url (archive_id ), headers = self .archive_headers (), timeout = self . timeout )
355
356
356
357
if response .status_code < 300 :
357
358
return Archive (self , response .json ())
@@ -380,7 +381,7 @@ def get_archives(self, offset=None, count=None):
380
381
if count is not None :
381
382
params ['count' ] = count
382
383
383
- response = requests .get (self .archive_url () + "?" + urlencode (params ), headers = self .archive_headers ())
384
+ response = requests .get (self .archive_url () + "?" + urlencode (params ), headers = self .archive_headers (), timeout = self . timeout )
384
385
385
386
if response .status_code < 300 :
386
387
return ArchiveList (self , response .json ())
0 commit comments