简体   繁体   English

用tor和硒获得新的身份。 出现错误“ IncorrectSocketType:无法使用控制套接字”

[英]Getting new identity with tor and selenium. got error “IncorrectSocketType: unable to use the control socket”

I'm trying to send a 'new identity' signal to tor using the stem module for python. 我正在尝试使用python的stem模块向tor发送一个“新身份”信号。 I got most of the code that got me to this point from reading other questions in stackoverflow but I can't seem to find a way to fix this error. 通过阅读stackoverflow中的其他问题,我得到了到此为止的大多数代码,但是我似乎找不到解决此错误的方法。 I want to be able to control tor with selenium and get a new identity any way possible. 我希望能够用硒控制tor并以任何可能的方式获得新身份。 I'm just using stem since it seems like the way to go from the research I've made but I'm open to change.(I'm on windows) 我只是在使用词干,因为这似乎是我进行的研究的出路,但我愿意改变。(我在Windows上)

I have tried changing 我尝试改变

profile.set_preference('network.proxy.socks_port', 9050)

from 9050 to 9051 but I get 90509051但我得到了

stem.SocketError: [WinError 10061] No connection could be made because the target machine actively refused it

I have looked at this post but I don't have any password set in my torrc file Unable to use Stem and Tor in Python to change my IP address? 我看了这篇文章,但是我的torrc文件中没有设置任何密码无法在Python中使用Stem和Tor来更改我的IP地址?

I have also tried changing to CookieAuthentication 0 but changed it back to 1 since no luck with that either. 我也曾尝试更改为CookieAuthentication 0但由于没有运气,因此将其更改回1

I open tor with selenium using this method: 我使用这种方法用硒打开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")

and tried making this method to call a new identity for tor: 并尝试使用此方法为tor调用新身份:

def new_identity():
    with Controller.from_port(port = 9050) as controller:
        controller.authenticate()
        controller.signal(Signal.NEWNYM)

my torrc file is also missing a lot of things from what I've seen on the internet but I have also read that I should be fine for it to look like this: 我在互联网上看到的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

the error im curently getting is: 即时得到的错误是:

raise IncorrectSocketType('unable to use the control socket')
stem.connection.IncorrectSocketType: unable to use the control socket

The default SocksPort is 9050, and the ControlPort (which is not enabled by default) is 9051. 默认的SocksPort是9050,而ControlPort (默认情况下未启用)是9051。

You'll need both of those configuration options in order to get what you want working. 您将需要这两个配置选项才能获得想要的工作。

The browser SOCKS config should use port 9050, and your Python code for stem should use 9051. To start, leave CookieAuthentication and PasswordAuthentication options out, so you should be able to connect locally without auth. 浏览器的SOCKS配置应使用端口9050,而您的Python代码则应使用9051。要启动,请保留CookieAuthentication和PasswordAuthentication选项,以便您无需身份验证即可本地连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM