I started with TOR's STEM library and I am trying to make the following code work but can't figure out the reason for the error.
Here's my code:
import stem
from stem.process import launch_tor
from stem.control import Controller
tor_path = ".\\Tor Browser\\Browser\\TorBrowser\\Tor\\tor.exe"
def print_lines(line):
if('Bootstrapped' in line):
print(line)
tor = launch_tor(tor_cmd = tor_path, init_msg_handler = print_lines)
try:
controller = Controller.from_port()
except stem.SocketError as exc:
print("Unable to connect to tor on port 9051: %s" % exc)
tor.kill()
And I am getting the following error:
Unable to connect to tor on port 9051: [WinError 10061] No connection could be made because the target machine actively refused it