本文介绍了无法在Python中使用Stem和Tor更改我的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试遵循我在此处在线找到的脚本:周期性Tor IP旋转

I am currently trying to follow the a script I found online here: 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地址不会因此改变.有谁知道如何修改它?谢谢.

However, my ip address doesn't change using this. Does anyone have any idea how I can modify it? Thanks.

推荐答案

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

You need to be give a password to the authenticate() function.

示例:

    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中使用Stem和Tor更改我的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:54