Skip to content

Commit c868bb4

Browse files
committed
gateway: Fix timeout when using api_request
1 parent ce542ac commit c868bb4

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

gateway.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def api_request(self, path, params = None, resp = 'json', post = '', timeout = 4
121121
url += f';stok={self.stok}/api' + path[3:]
122122
else:
123123
url += path
124-
t_timeout = (self.con_timeout, timeout)
124+
t_timeout = (self.con_timeout, timeout) if timeout is not None else (self.con_timeout, self.timeout)
125+
#print(f'{t_timeout=}')
125126
if post:
126127
response = requests.post(url, data = params, stream = stream, headers = headers, timeout = t_timeout)
127128
else:
@@ -337,34 +338,34 @@ def set_device_systime(self, dst, year = 0, month = 0, day = 0, hour = 0, min =
337338
sec = dst['sec']
338339
timezone = dst['timezone']
339340
params = { 'time': f"{year}-{month}-{day} {hour}:{min}:{sec}", 'timezone': timezone }
340-
dres = self.api_request('API/misystem/set_sys_time', params)
341+
dres = self.api_request('API/misystem/set_sys_time', params, timeout = self.timeout)
341342
if not dres or dres['code'] != 0:
342343
raise RuntimeError(f'Error on exec command "set_sys_time" => {dres}')
343344
if wait:
344345
time.sleep(3.1) # because internal code exec: "echo 'ok,xiaoqiang' > /tmp/ntp.status; sleep 3; date -s \""..time.."\""
345346
return True
346347

347-
def get_diag_paras(self):
348+
def get_diag_paras(self, timeout = None):
348349
# http://192.168.31.1/cgi-bin/luci/;stok=14b996378966455753104d187c1150b4/api/xqnetwork/diag_get_paras
349350
# response: {"code":0,"signal_thr":"-60","usb_read_thr":0,"disk_write_thr":0,"disk_read_thr":0,"iperf_test_thr":"25","usb_write_thr":0}
350-
dres = self.api_request('API/xqnetwork/diag_get_paras')
351+
dres = self.api_request('API/xqnetwork/diag_get_paras', timeout = timeout)
351352
if not dres or dres['code'] != 0:
352353
raise RuntimeError(f'Error on get diag_get_paras => {dres}')
353354
return dres
354355

355-
def get_diag_iperf_test_thr(self):
356-
resp = self.get_diag_paras()
356+
def get_diag_iperf_test_thr(self, timeout = None):
357+
resp = self.get_diag_paras(timeout = timeout)
357358
return str(resp['iperf_test_thr'])
358359

359-
def set_diag_iperf_test_thr(self, iperf_test_thr):
360+
def set_diag_iperf_test_thr(self, iperf_test_thr, timeout = None):
360361
params = {
361362
'iperf_test_thr': str(iperf_test_thr),
362363
'usb_read_thr': 0,
363364
'usb_write_thr': 0,
364365
'disk_read_thr': 0,
365366
'disk_write_thr': 0,
366367
}
367-
dres = self.api_request('API/xqnetwork/diag_set_paras', params)
368+
dres = self.api_request('API/xqnetwork/diag_set_paras', params, timeout = timeout)
368369
if not dres or dres['code'] != 0:
369370
raise RuntimeError(f'Error on exec command "diag_set_paras" => {dres}')
370371
return True

0 commit comments

Comments
 (0)