【问题标题】:How to get Tor relay info via python + stem on linux?如何在 Linux 上通过 python + stem 获取 Tor 中继信息?
【发布时间】:2014-03-30 17:04:43
【问题描述】:

我正在尝试按照 tor 的website 上的说明使用 python 的 stem 库来控制 ubuntu linux 上的 tor。但是,当我运行建议的 python 代码时

from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
    controller.authenticate()  # provide the password here if you set one

    bytes_read = controller.get_info("traffic/read")

    bytes_written = controller.get_info("traffic/written")

    print "My Tor relay has read %s bytes and written %s." % (bytes_read, bytes_written)

我得到错误:

Traceback(最近一次调用最后一次):

模块中的文件“littleRelay.py”,第 5 行

bytes_read = controller.get_info("traffic/read")

文件“/usr/local/lib/python2.7/dist-packages/stem/control.py”,第 852 行,在 get_info 中

提高exc

stem.InvalidArguments:GETINFO 请求包含无法识别的关键字:traffic/read

那么如何在 Linux 上通过 python+stem 获取 Tor 中继信息? 我认为 Tor 运行良好,因为我从终端启动了 Tor,它说

[notice] Tor 已成功打开电路。看起来客户端功能正在运行。

[notice] 自举 100%:完成。

此外,当我运行上面的 python 代码时,终端会说

[notice] 新的控制连接打开。

附:我还在 Windows pc 上尝试过代码,它工作正常。我现在真的很困惑。

【问题讨论】:

  • 那没用,但谢谢安德烈。

标签: python linux tor


【解决方案1】:

该错误表明 Tor 不支持“GETINFO traffic/read”查询。这很奇怪——这是我在 2011 年添加到 Tor 的一个功能。也许你的 Tor 副本已经非常非常过时了?

【讨论】:

    【解决方案2】:

    问题解决了!谢谢达米安!

    我在 Ubuntu 上卸载了 Tor,然后按照详细指南 here 重新安装了 Tor。现在 Tor 可以使用 python 代码了。

    我不确定问题到底是如何产生的,但我认为问题与在 Ubuntu 上安装 Tor 天真的使用有关

    sudo apt-get install tor

    【讨论】:

    • 明白了。这实际上很好,但如果你有一个旧的发行版,那么你会得到一个旧的 Tor 实例。 Ubuntu 会在 Debian 存储库发布新版本时对其进行快照,例如,您的 Ubuntu 副本是在 2010 年发布的,那么您可能会拥有 2010 年的 Tor 副本。
    猜你喜欢
    • 1970-01-01
    • 2014-09-08
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多