0

我正在使用 Stem 启动 Tor 进程。使用To Russia with love教程作为指南。这是代码:

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),
    },
)

给出一个错误:

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

有什么解决办法吗?

4

1 回答 1

0

尝试将 tor.exe 添加到 Windows PATH 系统变量,然后运行以下代码:

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

这对我来说很好。

哦,请确保 tor.exe 没有在 Windows 进程管理器中运行。

于 2015-07-04T22:44:47.360 回答