0

I am using Stem to start a Tor process. Using the To Russia with love tutorial as a guide. This is the code:

import requests
import socket
import socks
import stem.process

SOCKS_PORT = 9150

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT)
socket.socket = socks.socksocket

tor_process = stem.process.launch_tor_with_config(
tor_cmd = 'C:\Users\Sachin Kelkar\Desktop\Tor Browser\Browser\TorBrowser\Tor\\tor.exe',
config={
    'SocksPort': str(SOCKS_PORT),
    },
)

Gives an error:

Traceback (most recent call last):
  File "<pyshell#17>", line 4, in <module>
    'SocksPort': str(SOCKS_PORT),
  File "C:\Python27\lib\site-packages\stem\process.py", line 255, in launch_tor_with_config
return launch_tor(tor_cmd, ['-f', '-'], None, completion_percent, init_msg_handler, timeout, take_ownership, stdin = config_str)
  File "C:\Python27\lib\site-packages\stem\process.py", line 142, in launch_tor
tor_process.kill()  # ... but best make sure
  File "C:\Python27\lib\subprocess.py", line 1001, in terminate
_subprocess.TerminateProcess(self._handle, 1)
WindowsError: [Error 5] Access is denied

Any solutions to this?

Sachin Kelkar
  • 1,282
  • 2
  • 11
  • 16

1 Answers1

0

Try to add tor.exe to Windows PATH system variable, and then run this code:

def print_bootstrap_lines(line):
  if "Bootstrapped " in line:
    print(line)

tor_process = stem.process.launch_tor_with_config(
  config = {
    'SocksPort': str(SOCKS_PORT),
    #'ExitNodes': '{au}',
  },
  init_msg_handler = print_bootstrap_lines,
)

It's works for me fine.

Oh, and be sure that tor.exe is not running in the Windows Process Manager.

Abraham Tugalov
  • 1,902
  • 18
  • 25