【问题标题】:Sending a signal to stem closes the socket向 stem 发送信号会关闭套接字
【发布时间】:2018-06-02 14:41:02
【问题描述】:

这段代码:

from stem import Signal
from stem.control import Controller

with Controller.from_port(port=9051) as controller:
    print('is alive BEFORE ? ')
    print(controller.is_alive())
    try:
        controller.signal(Signal.HEARTBEAT)
    except Exception as e:
        print(e)
    print('is alive AFTER ? ')
    print(controller.is_alive())

with Controller.from_port(port=9051) as controller:
    print('is alive 2 ? ')
    print(controller.is_alive())

产生这个输出:

is alive BEFORE ?
True
SIGNAL response contained unrecognized status code: 514
is alive AFTER ?
False
is alive 2 ?
True

并且没有记录心跳。此外,如果我在发送信号后尝试向 tor 发出请求,则会得到:[stem] INFO: Error while received a control message (SocketClosed): empty socket content

Tor 配置为: 袜口 9050 控制端口 9051

【问题讨论】:

  • 这里没有关闭套接字的证据。

标签: python networking tor stem


【解决方案1】:

514 错误表示Authentication required

连接后,首先要做的就是认证:

with Controller.from_port(port=9051) as controller:
    print('is alive BEFORE ? ')
    print(controller.is_alive())
    controller.authenticate()
    ...

另请注意,Tor 会在身份验证失败后关闭连接。请参阅control spec 第 3.5 节了解更多信息。

第一个词干示例更详细地介绍了这些基础知识:https://stem.torproject.org/tutorials/the_little_relay_that_could.html

【讨论】:

    猜你喜欢
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多