7

I have installed Tor to run as a service on my windows machine and I am trying to make requests in python through the Stem package. In my torrc file I have specified ControlPort as 9051 and set a HashedControlPassword. When I run netstat, I see that Tor is running on localhost:9050 but there is nothing listening to port 9051. As a result, when I try to connect to the ControlPort in python:

Controller.from_port(port=9051)

results in a

[Errno 10061] No connection could be made because the target machine actively refused it

I've tried restarting the service, I even reinstalled Tor Browser but nothing seems to make the ControlPort work.

AChampion
  • 29,683
  • 4
  • 59
  • 75
Einstein
  • 431
  • 1
  • 5
  • 12
  • 1
    Firewall issue? When you get it working you may want to use a `context_manager` form: `with Controller.from_port(port = 9051) as controller: controller.authenticate(password="")` – AChampion Aug 31 '17 at 03:33

2 Answers2

18

the problem you have is because you are running tor as a Windows Service. The issue is that when tor is installed as a service, for whatever reason the Control Port is not enabled. To fix your issue, open your terminal, navigate to the tor directory and type the following commands:

tor --service remove
tor --service install -options ControlPort 9051

Now, tor is installed as a service AND the ControlPort is enabled on port 9051. If you type "netstat -an" you will now see that port 9051 is open.

You will then be able to use Stem to connect to the ControlPort.

I hope this helps.

Peace. Sat Cit Ananda.

Sat Cit Ananda
  • 230
  • 4
  • 10
  • 4
    Yeah, it is strange, I lost a whole afternoon figuring out the cause of the issue and how to resolve it. Glad I could help you, and maybe other who will face the same issue in the future. – Sat Cit Ananda Sep 19 '17 at 20:16
  • 1
    there are several tor folders, the path needed is `...\Tor Browser\Browser\TorBrowser\Tor` – JinSnow Oct 25 '17 at 21:29
  • I'm not seeing port "9051" open after following the installation process and entering in "netstat -an" in the terminal. I'm also not seeing port "9050" which is throwing a connection error when making the initial "session.get()" request... Any input is appreciated. You're my hero! – philiporlando Nov 23 '17 at 01:21
  • I keep getting "Service failed to start : An exception occurred in the service when handling the control request." error, but cant figure out why, any tips? – no nein Oct 10 '20 at 20:20
2

Solution that worked for me (windows 10) with a bit of tweaking from Sat Cit Ananda's answer:

[at your terminal]
cd ...\Tor Browser\Browser\TorBrowser\Tor
tor --service remove
tor --service install -options ControlPort 9151
netstat -an

Tor service runs at default port 9150 and ControlPort on 9151. You should be able to see local address 127.0.0.1:9150 and 127.0.0.1:9151 when you run netstat -an.

KittyBot
  • 41
  • 2