From af3ee66cd74ab86c8b8b58acc5c7bad121a1caa5 Mon Sep 17 00:00:00 2001 From: Kailigithub Date: Tue, 5 May 2026 03:08:55 +0000 Subject: [PATCH] fix: add request timeout and replace assert with proper exception --- TMWebDriver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TMWebDriver.py b/TMWebDriver.py index 02a185b1..6a4a704a 100644 --- a/TMWebDriver.py +++ b/TMWebDriver.py @@ -204,7 +204,8 @@ class TMWebDriver: raise ValueError(f"会话ID {session_id} 未连接") tp = session.type - assert tp in ['ws', 'http', 'ext_ws'], f"Unsupported session type: {tp}" + if tp not in ('ws', 'http', 'ext_ws'): + raise ValueError(f"Unsupported session type: {tp}") exec_id = str(uuid.uuid4()) payload_dict = {'id': exec_id, 'code': code} if tp == 'ext_ws': payload_dict['tabId'] = int(session.id) @@ -243,7 +244,7 @@ class TMWebDriver: return rr def _remote_cmd(self, cmd): - try: return requests.post(self.remote, headers={"Content-Type": "application/json"}, json=cmd).json() + try: return requests.post(self.remote, headers={"Content-Type": "application/json"}, json=cmd, timeout=30).json() except (ConnectionError, requests.exceptions.ConnectionError): raise ConnectionError("TMWebDriver master未运行,看tmwebdriver_sop启动master")