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

有些话、适合烂在心里 提交于 2019-12-24 08:22:45

问题


I am currently trying to follow the a script I found online here: Periodic Tor IP Rotation

The code I am trying to use is the following:

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)

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


回答1:


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

Example:

    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")


来源:https://stackoverflow.com/questions/52012449/unable-to-use-stem-and-tor-in-python-to-change-my-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!