stem.connection.IncorrectSocketType:无法使用控制插座

2024-04-25 23:55:47 发布

您现在位置:Python中文网/ 问答频道 /正文

试图通过Tor发送requests[socks]请求,并在x请求量之后续订IP

代码如下:

def tor():
    session = requests.session()
    session.proxies = {'http': 'socks5://127.0.0.1:9050',
                       'https': 'socks5://127.0.0.1:9050'}
    return session

session = tor()

def renew_tor_ip():
    with Controller.from_port(port = 9050) as controller:
        controller.authenticate(password="mypassword")
        controller.signal(Signal.NEWNYM)

def get_dorks(pages):
    for i in range(pages):
        i += 1
        if i == 0:
            s = session.get("url")
        if i != 0:
            s = session.get("url" + str(i))
            if i == 20:
                renew_tor_ip()

当我运行这个时

stem.connection.IncorrectSocketType: unable to use the control socket

编辑:在stem的“一个小继电器”文章之后,我更改了我的TORC文件

edit2:尚未找到解决方案


Tags: ipurlgetifportsessiondefpages
1条回答
网友
1楼 · 发布于 2024-04-25 23:55:47

9050不是控制器的端口。 9051是您正在寻找的端口

改变with Controller.from_port(port = 9050) as controllerwith Controller.from_port(port = 9051) as controller

您还必须在tor的配置文件中启用端口

相关问题 更多 >