0

这段代码:

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 配置为:SocksPort 9050 ControlPort 9051

4

1 回答 1

0

514错误的意思是Authentication required

连接后,您必须做的第一件事是进行身份验证:

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

另请注意,Tor 会在身份验证失败后关闭连接。 有关详细信息,请参阅控制规范第 3.5 节。

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

于 2018-06-04T00:59:21.297 回答