无法使用干以及Tor在Python改变我的IP地址?

问题描述 投票:1回答:1

目前我正在试图遵循一个脚本我在网上找到的位置: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地址不会改变用本品。没有人有任何想法,我怎么可以修改?谢谢。

python python-3.x tor stem
1个回答
1
投票

您需要将身份验证()函数来得到一个密码。

例:

    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")
© www.soinside.com 2019 - 2024. All rights reserved.