我正在尝试使用 python 的 stem 模块向 tor 发送“新身份”信号。我通过阅读stackoverflow中的其他问题获得了大部分代码,但我似乎找不到解决此错误的方法。我希望能够用 selenium 控制 tor 并以任何可能的方式获得新的身份。我只是使用stem,因为它似乎是我所做研究的一种方式,但我愿意改变。(我在windows上)
我试过改变
profile.set_preference('network.proxy.socks_port', 9050)
从9050
到9051
但我得到
stem.SocketError: [WinError 10061] No connection could be made because the target machine actively refused it
我看过这篇文章,但我的 torrc 文件中没有设置任何密码 无法在 Python 中使用 Stem 和 Tor 来更改我的 IP 地址?
我也尝试过更改为,CookieAuthentication 0
但将其更改回,1
因为也没有运气。
我使用这种方法用 selenium 打开 tor:
def setup():
torexe = os.popen(r'D:\Program files\tor\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'D:\Program files\tor\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\Windows\geckodriver.exe')
driver.get("http://check.torproject.org")
并尝试使用此方法为 tor 调用新身份:
def new_identity():
with Controller.from_port(port = 9050) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
我的 torrc 文件也缺少我在互联网上看到的很多东西,但我也读到我应该可以让它看起来像这样:
# This file was generated by Tor; if you edit it, comments will not be preserved
# The old torrc file was renamed to torrc.orig.1 or similar, and Tor will ignore it
ControlPort 9050
CookieAuthentication 0
DataDirectory D:\Program files\tor\Tor Browser\Browser\TorBrowser\Data\Tor
GeoIPFile D:\Program files\tor\Tor Browser\Browser\TorBrowser\Data\Tor\geoip
GeoIPv6File D:\Program files\tor\Tor Browser\Browser\TorBrowser\Data\Tor\geoip6
我目前得到的错误是:
raise IncorrectSocketType('unable to use the control socket')
stem.connection.IncorrectSocketType: unable to use the control socket