當前位置: 首頁>>代碼示例>>Python>>正文


Python websocket.WebSocketConnectionClosedException方法代碼示例

本文整理匯總了Python中websocket.WebSocketConnectionClosedException方法的典型用法代碼示例。如果您正苦於以下問題:Python websocket.WebSocketConnectionClosedException方法的具體用法?Python websocket.WebSocketConnectionClosedException怎麽用?Python websocket.WebSocketConnectionClosedException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在websocket的用法示例。


在下文中一共展示了websocket.WebSocketConnectionClosedException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testInternalRecvStrict

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testInternalRecvStrict(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        s.add_packet(six.b("foo"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("bar"))
        # s.add_packet(SSLError("The read operation timed out"))
        s.add_packet(six.b("baz"))
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.frame_buffer.recv_strict(9)
        # if six.PY2:
        #     with self.assertRaises(ws.WebSocketTimeoutException):
        #         data = sock._recv_strict(9)
        # else:
        #     with self.assertRaises(SSLError):
        #         data = sock._recv_strict(9)
        data = sock.frame_buffer.recv_strict(9)
        self.assertEqual(data, six.b("foobarbaz"))
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.frame_buffer.recv_strict(1) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:test_websocket.py

示例2: testRecvTimeout

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testRecvTimeout(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        s.add_packet(six.b("\x81"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("\x8dabcd\x29\x07\x0f\x08\x0e"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("\x4e\x43\x33\x0e\x10\x0f\x00\x40"))
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.recv()
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.recv()
        data = sock.recv()
        self.assertEqual(data, "Hello, World!")
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.recv() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_websocket.py

示例3: testRecvWithFireEventOfFragmentation

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testRecvWithFireEventOfFragmentation(self):
        sock = ws.WebSocket(fire_cont_frame=True)
        s = sock.sock = SockMock()
        # OPCODE=TEXT, FIN=0, MSG="Brevity is "
        s.add_packet(six.b("\x01\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C"))
        # OPCODE=CONT, FIN=0, MSG="Brevity is "
        s.add_packet(six.b("\x00\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C"))
        # OPCODE=CONT, FIN=1, MSG="the soul of wit"
        s.add_packet(six.b("\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17"))

        _, data = sock.recv_data()
        self.assertEqual(data, six.b("Brevity is "))
        _, data = sock.recv_data()
        self.assertEqual(data, six.b("Brevity is "))
        _, data = sock.recv_data()
        self.assertEqual(data, six.b("the soul of wit"))

        # OPCODE=CONT, FIN=0, MSG="Brevity is "
        s.add_packet(six.b("\x80\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C"))

        with self.assertRaises(ws.WebSocketException):
            sock.recv_data()

        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.recv() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:27,代碼來源:test_websocket.py

示例4: testRecvWithProlongedFragmentation

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testRecvWithProlongedFragmentation(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        # OPCODE=TEXT, FIN=0, MSG="Once more unto the breach, "
        s.add_packet(six.b("\x01\x9babcd.\x0c\x00\x01A\x0f\x0c\x16\x04B\x16\n\x15"
                           "\rC\x10\t\x07C\x06\x13\x07\x02\x07\tNC"))
        # OPCODE=CONT, FIN=0, MSG="dear friends, "
        s.add_packet(six.b("\x00\x8eabcd\x05\x07\x02\x16A\x04\x11\r\x04\x0c\x07"
                           "\x17MB"))
        # OPCODE=CONT, FIN=1, MSG="once more"
        s.add_packet(six.b("\x80\x89abcd\x0e\x0c\x00\x01A\x0f\x0c\x16\x04"))
        data = sock.recv()
        self.assertEqual(
            data,
            "Once more unto the breach, dear friends, once more")
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.recv() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:test_websocket.py

示例5: sendRequest

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def sendRequest(self, channel, params):
        """發送指令請求"""
        print(u'vnokex.sendRequest:{}'.format(channel))
        # 在參數字典中加上api_key和簽名字段
        params['api_key'] = self.apiKey
        params['sign'] = self.generateSign(params)

        # 生成請求
        d = {}
        d['event'] = 'addChannel'
        d['channel'] = channel
        d['parameters'] = params

        # 使用json打包並發送
        j = json.dumps(d)

        # 若觸發異常則重連
        try:
            self.ws.send(j)
        except websocket.WebSocketConnectionClosedException as ex:
            print(u'vnokex.sendTradingRequest Exception:{}'.format(str(ex)),file=sys.stderr)

    #---------------------------------------------------------------------- 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:vnokex.py

示例6: sendTradingRequest

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def sendTradingRequest(self, channel, params):
        """發送交易請求"""
        # 在參數字典中加上api_key和簽名字段
        params['api_key'] = self.apiKey
        params['sign'] = self.generateSign(params)

        # 生成請求
        d = {}
        d['event'] = 'addChannel'
        d['channel'] = channel
        d['parameters'] = params

        # 使用json打包並發送
        j = json.dumps(d)

        # 若觸發異常則重連
        try:
            self.ws.send(j)
        except websocket.WebSocketConnectionClosedException as ex:
            print(u'OkexContractApi.sendTradingRequest exception:{},{}'.format(str(ex),traceback.format_exc()), file=sys.stderr)
        except Exception as ex:
            print(u'OkexContractApi.sendTradingRequest exception:{},{}'.format(str(ex), traceback.format_exc()), file=sys.stderr)

    # ---------------------------------------------------------------------- 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:26,代碼來源:vnokex.py

示例7: _safe_send

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def _safe_send(self, data, force=False):
        if not self.alive and not force:
            # Try to wait a second to send a packet
            timeout = 1
            while timeout > 0 and not self.alive:
                time.sleep(0.1)
                timeout -= 0.1
            if not self.alive:
                # don't try to send a packet if we're still dead
                return False
        try:
            self.ws.send(data)
        except websocket.WebSocketConnectionClosedException:
            # The channel died mid-send, wait for it to come back up
            return False
        return True 
開發者ID:facebookresearch,項目名稱:ParlAI,代碼行數:18,代碼來源:socket.py

示例8: _send_to_timeseries

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def _send_to_timeseries(self, message):
        """
        Establish or reuse socket connection and send
        the given message to the timeseries service.
        """
        logging.debug("MESSAGE=" + str(message))

        result = None
        try:
            ws = self._get_websocket()
            ws.send(json.dumps(message))
            result = ws.recv()
        except (websocket.WebSocketConnectionClosedException, Exception) as e:
            logging.debug("Connection failed, will try again.")
            logging.debug(e)

            ws = self._get_websocket(reuse=False)
            ws.send(json.dumps(message))
            result = ws.recv()

        logging.debug("RESULT=" + str(result))
        return result 
開發者ID:PredixDev,項目名稱:predixpy,代碼行數:24,代碼來源:timeseries.py

示例9: recv

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def recv(self):
        if not self.client.connected:
            self._try_to_establish_connection()
        while self._is_active():
            try:
                data = self.client.recv()
                self._on_successful_connect()
                return data
            except WebSocketTimeoutException:
                raise
            except WebSocketConnectionClosedException:
                if self._is_active():
                    self._handle_lost_connection()
                else:
                    raise
            except WebsocketNotConnectedException:
                if self._is_active():
                    self._handle_lost_connection()
            except Exception:
                if self._is_active():
                    self._handle_lost_connection() 
開發者ID:neptune-ai,項目名稱:neptune-client,代碼行數:23,代碼來源:reconnecting_websocket.py

示例10: send

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def send(self, api_key=None, secret=None, list_data=None, auth=False, **kwargs):
        """Sends the given Payload to the API via the websocket connection.

        :param kwargs: payload paarameters as key=value pairs
        :return:
        """
        if auth:
            nonce = str(int(time.time() * 10000000))
            auth_string = 'AUTH' + nonce
            auth_sig = hmac.new(secret.encode(), auth_string.encode(),
                                hashlib.sha384).hexdigest()

            payload = {'event': 'auth', 'apiKey': api_key, 'authSig': auth_sig,
                       'authPayload': auth_string, 'authNonce': nonce}
            payload = json.dumps(payload)
        elif list_data:
            payload = json.dumps(list_data)
        else:
            payload = json.dumps(kwargs)
        self.log.debug("send(): Sending payload to API: %s", payload)
        try:
            self.socket.send(payload)
        except websocket.WebSocketConnectionClosedException:
            self.log.error("send(): Did not send out payload %s - client not connected. ", kwargs) 
開發者ID:Crypto-toolbox,項目名稱:btfxwss,代碼行數:26,代碼來源:connection.py

示例11: ___recv

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def ___recv(self, tab_key, timeout=None):

		try:
			if timeout:
				self.soclist[tab_key].settimeout(timeout)

			tmp = self.soclist[tab_key].recv()
			self.log.debug("		Received: '%s'", tmp)

			decoded = json.loads(tmp)
			return decoded
		except (socket.timeout, websocket.WebSocketTimeoutException):
			return None
		except websocket.WebSocketConnectionClosedException:
			raise cr_exceptions.ChromeCommunicationsError("Websocket appears to have been closed. Is the"
				" remote chromium instance dead?")
		finally:
			self.soclist[tab_key].settimeout(self.websocket_timeout) 
開發者ID:fake-name,項目名稱:ChromeController,代碼行數:20,代碼來源:transport.py

示例12: _disconnect

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def _disconnect(self):
        try:
            if self.ws:
                self.ws.close()
        except WebSocketConnectionClosedException as e:
            pass

        self.on_close() 
開發者ID:kkuette,項目名稱:TradzQAI,代碼行數:10,代碼來源:websocket_client.py

示例13: connect

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def connect(self):
        url = self.host_url
        try:
            self.ws = websocket.create_connection(url,
                                                  skip_utf8_validation=True)
        except socket.error as e:
            raise exception.ConnectionFailed(e)
        except websocket.WebSocketConnectionClosedException as e:
            raise exception.ConnectionFailed(e)
        except websocket.WebSocketBadStatusException as e:
            raise exception.ConnectionFailed(e) 
開發者ID:openstack,項目名稱:zun,代碼行數:13,代碼來源:websocketclient.py

示例14: testRecvWithSimpleFragmentation

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testRecvWithSimpleFragmentation(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        # OPCODE=TEXT, FIN=0, MSG="Brevity is "
        s.add_packet(six.b("\x01\x8babcd#\x10\x06\x12\x08\x16\x1aD\x08\x11C"))
        # OPCODE=CONT, FIN=1, MSG="the soul of wit"
        s.add_packet(six.b("\x80\x8fabcd\x15\n\x06D\x12\r\x16\x08A\r\x05D\x16\x0b\x17"))
        data = sock.recv()
        self.assertEqual(data, "Brevity is the soul of wit")
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.recv() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:13,代碼來源:test_websocket.py

示例15: testAfterClose

# 需要導入模塊: import websocket [as 別名]
# 或者: from websocket import WebSocketConnectionClosedException [as 別名]
def testAfterClose(self):
        s = ws.create_connection("ws://echo.websocket.org/")
        self.assertNotEqual(s, None)
        s.close()
        self.assertRaises(ws.WebSocketConnectionClosedException, s.send, "Hello")
        self.assertRaises(ws.WebSocketConnectionClosedException, s.recv) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:8,代碼來源:test_websocket.py


注:本文中的websocket.WebSocketConnectionClosedException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。