无法在 Python 中使用 Stem 和 Tor 更改我的 IP 地址?

Unable to use Stem and Tor in Python to change my IP address?

我目前正在尝试遵循我在此处在线找到的脚本:Periodic Tor IP Rotation

我尝试使用的代码如下:

import requests
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)
proxies = {
  "http": "http://127.0.0.1:8118"
}
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)
print(r.text)

但是,我的 IP 地址并没有改变。有谁知道我该如何修改它?谢谢

您需要为 authenticate() 函数提供密码。

示例:

    with Controller.from_port(port=9051) as controller:
        controller.authenticate(password='tor') # password came from your torrc file
        print("Success!")
        controller.signal(Signal.NEWNYM)
        print("New Tor connection processed")