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


Python stem.SocketError方法代碼示例

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


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

示例1: connect

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def connect(self, tor_password):
        try:
            self._controller = Controller.from_port()
        except stem.SocketError as exc:
            self._log.error("Unable to connect to tor on port 9051: %s" % exc)
            return False

        try:
            self._controller.authenticate(password=tor_password)
        except stem.connection.MissingPassword:
            self._log.error("Unable to authenticate, missing password")
            return False
        except stem.connection.AuthenticationFailure as exc:
            self._log.error("Unable to authenticate: %s" % exc)
            return False

        return True 
開發者ID:arrase,項目名稱:TOR-Hidden-Service-Verification,代碼行數:19,代碼來源:HiddenService.py

示例2: from_port

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def from_port(address = '127.0.0.1', port = 9051):
    """
    Constructs a :class:`~stem.socket.ControlPort` based Controller.

    :param str address: ip address of the controller
    :param int port: port number of the controller

    :returns: :class:`~stem.control.Controller` attached to the given port

    :raises: :class:`stem.SocketError` if we're unable to establish a connection
    """

    if not stem.util.connection.is_valid_ipv4_address(address):
      raise ValueError('Invalid IP address: %s' % address)
    elif not stem.util.connection.is_valid_port(port):
      raise ValueError('Invalid port: %s' % port)

    control_port = stem.socket.ControlPort(address, port)
    return Controller(control_port) 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:21,代碼來源:control.py

示例3: get_protocolinfo

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def get_protocolinfo(self, default = UNDEFINED):
    """
    get_protocolinfo(default = UNDEFINED)

    A convenience method to get the protocol info of the controller.

    :param object default: response if the query fails

    :returns: :class:`~stem.response.protocolinfo.ProtocolInfoResponse` provided by tor

    :raises:
      * :class:`stem.ProtocolError` if the PROTOCOLINFO response is
        malformed
      * :class:`stem.SocketError` if problems arise in establishing or
        using the socket

      An exception is only raised if we weren't provided a default response.
    """

    import stem.connection
    return stem.connection.get_protocolinfo(self) 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:23,代碼來源:control.py

示例4: __init__

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def __init__(self, address = '127.0.0.1', port = 9051, connect = True):
    """
    ControlPort constructor.

    :param str address: ip address of the controller
    :param int port: port number of the controller
    :param bool connect: connects to the socket if True, leaves it unconnected otherwise

    :raises: :class:`stem.SocketError` if connect is **True** and we're
      unable to establish a connection
    """

    super(ControlPort, self).__init__()
    self._control_addr = address
    self._control_port = port

    if connect:
      self.connect() 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:20,代碼來源:socket.py

示例5: authenticate_to_tor_controlport

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def authenticate_to_tor_controlport(self):
        self.logger.info("Authenticating to the tor controlport...")
        try:
            self.controller = Controller.from_port(port=self.control_port)
        except stem.SocketError as exc:
            panic("Unable to connect to tor on port {self.control_port}: "
                  "{exc}".format(**locals()))
        try:
            self.controller.authenticate()
        except stem.connection.MissingPassword:
            panic("Unable to authenticate to tor controlport. Please add "
                  "`CookieAuth 1` to your tor configuration file.") 
開發者ID:freedomofpress,項目名稱:fingerprint-securedrop,代碼行數:14,代碼來源:crawler.py

示例6: connect

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def connect(self):
    """
    Reconnects our control socket. This is a pass-through for our socket's
    :func:`~stem.socket.ControlSocket.connect` method.

    :raises: :class:`stem.SocketError` if unable to make a socket
    """

    self._socket.connect() 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:11,代碼來源:control.py

示例7: from_socket_file

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def from_socket_file(path = '/var/run/tor/control'):
    """
    Constructs a :class:`~stem.socket.ControlSocketFile` based Controller.

    :param str path: path where the control socket is located

    :returns: :class:`~stem.control.Controller` attached to the given socket file

    :raises: :class:`stem.SocketError` if we're unable to establish a connection
    """

    control_socket = stem.socket.ControlSocketFile(path)
    return Controller(control_socket) 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:15,代碼來源:control.py

示例8: send

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def send(self, message, raw = False):
    """
    Formats and sends a message to the control socket. For more information see
    the :func:`~stem.socket.send_message` function.

    :param str message: message to be formatted and sent to the socket
    :param bool raw: leaves the message formatting untouched, passing it to the socket as-is

    :raises:
      * :class:`stem.SocketError` if a problem arises in using the socket
      * :class:`stem.SocketClosed` if the socket is known to be shut down
    """

    with self._send_lock:
      try:
        if not self.is_alive():
          raise stem.SocketClosed()

        send_message(self._socket_file, message, raw)
      except stem.SocketClosed as exc:
        # if send_message raises a SocketClosed then we should properly shut
        # everything down

        if self.is_alive():
          self.close()

        raise exc 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:29,代碼來源:socket.py

示例9: _make_socket

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def _make_socket(self):
    """
    Constructs and connects new socket. This is implemented by subclasses.

    :returns: **socket.socket** for our configuration

    :raises:
      * :class:`stem.SocketError` if unable to make a socket
      * **NotImplementedError** if not implemented by a subclass
    """

    raise NotImplementedError('Unsupported Operation: this should be implemented by the ControlSocket subclass') 
開發者ID:Tycx2ry,項目名稱:llk,代碼行數:14,代碼來源:socket.py

示例10: get_exit

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def get_exit(is_running):
   """
   Get list of exit node from stem
   """
   if is_running:
      try:
         with Controller.from_port(port = 6969) as controller:
            controller.authenticate()
            exit = {'count': [], 'fingerprint': [], 'nickname': [], 'ipaddress': []}
            count = -1
            for circ in controller.get_circuits():
               if circ.status != stem.CircStatus.BUILT:
                  continue
               exit_fp, exit_nickname = circ.path[-1]
               exit_desc = controller.get_network_status(exit_fp, None)
               exit_address = exit_desc.address if exit_desc else 'unknown'
               count += 1
               exit['count'].append(count)
               exit['fingerprint'].append(exit_fp)
               exit['nickname'].append(exit_nickname)
               exit['ipaddress'].append(exit_address)
         return exit
      except stem.SocketError as exc:
         notify("TorTP", "[!] Unable to connect to port 6969 (%s)" % exc)
         sys.exit(1)
   else:
      notify("TorTP", "[!] Tor is not running")
      sys.exit(0) 
開發者ID:stevensshi,項目名稱:smart-realestate,代碼行數:30,代碼來源:tortp.py

示例11: tor_new

# 需要導入模塊: import stem [as 別名]
# 或者: from stem import SocketError [as 別名]
def tor_new():
   """
   Create a new tor circuit
   """
   try:
      stem.socket.ControlPort(port = 6969)
   except stem.SocketError as exc:
      notify("TorTP", "[!] Unable to connect to port 6969 (%s)" % exc)
      sys.exit(1)
   with Controller.from_port(port = 6969) as controller:
      controller.authenticate()
      controller.signal(stem.Signal.NEWNYM)
      notify("TorTP", "[+] New Tor circuit created") 
開發者ID:stevensshi,項目名稱:smart-realestate,代碼行數:15,代碼來源:tortp.py


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