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

标签 python python-3.x tor stem

我目前正在尝试遵循我在网上找到的脚本: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")

关于python - 无法在 Python 中使用 Stem 和 Tor 更改我的 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52012449/

相关文章:

python - 使用 TOR 运行 python 脚本

python - 值错误: too many values to unpack while parsing the txt

python - 如何 Python 从包含分号的配置文件中打印一行?

python - 类型对象 'Questions' 没有属性 'objects'

python - await 如何在协程链接期间将控制权交还给事件循环?

python-3.x - 从 Python 2 移植到 Python 3 : 'utf-8 codec can' t decode byte'

linux - 如何使用 GTK、python 和 glade 制作单窗口程序?

linux - Tor 浏览器 bundle 无法建立连接

http - 无法在golang中使用socks5代理-读取: connection reset by peer

Python提取动态文本格式的文本数据