Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t使用privoxy和stem从Tor获得新ip_Python_Web Scraping_Tor - Fatal编程技术网

Python Can';t使用privoxy和stem从Tor获得新ip

Python Can';t使用privoxy和stem从Tor获得新ip,python,web-scraping,tor,Python,Web Scraping,Tor,我试着用Tor、Privoxy和Stem来旋转ip,但最终得到的ip总是相同的。我尝试过几种方法(更改代理、使用请求会话等等),但都没有成功 这是我的python代码: import requests from stem import Signal from stem.control import Controller with Controller.from_port(port = 9051) as controller: controller.authenticate('mykey')

我试着用Tor、Privoxy和Stem来旋转ip,但最终得到的ip总是相同的。我尝试过几种方法(更改代理、使用请求会话等等),但都没有成功

这是我的python代码:

import requests
from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate('mykey')
  controller.signal(Signal.NEWNYM)

#proxies = {
#  "http": "http://127.0.0.1:8118"
#}

proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}

headers = {
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11'
}
r = requests.get("http://icanhazip.com", proxies=proxies, headers=headers, stream=False)
print (r.text)
.torc文件具有此配置

ExitNodes {ar}
StrictNodes 1

ControlPort 9051
HashedControlPassword 16:BA2B8B2EAC4B391060A6FAA27FA922706F08D0BA0115D79840265D9DC3
privoxy配置文件包含以下行

forward-socks5   /               127.0.0.1:9050 .

我发现下面的方法非常方便和有用,而不是你上面尝试的方法。确保将
tor.exe
文件的正确位置放在
torexe
变量中。概念证明:

import requests
import os

torexe = os.popen(r"C:\Users\WCS\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe")

with requests.Session() as s:
    s.proxies['http']  = 'socks5h://localhost:9050'
    res = s.get("http://icanhazip.com")
    print(res.text)

torexe.close()

我发现了问题所在。IP路由工作正常,问题是我一直在使用来自{ar}的ExitNodes,而阿根廷只有一个节点。所以,它总是相同的IP。

问题是我没有使用Windows。