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")