当前位置: 首页>>代码示例>>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;未经允许,请勿转载。