TOR系统没有找到cookie控制认证文件



我用的是Windows 10。我有Tor Win32服务正在运行。

这是我从C:…浏览器 Tor浏览器 TorBrowser Tor torrc数据

ControlPort 9051
CookieAuthentication 1
CacheDirectoryGroupReadable 1
下面是我的python 3.9代码:
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)

运行脚本生成以下堆栈跟踪:

Traceback (most recent call last):
File "<input>", line 2, in <module>
File "C:UsersShaunPycharmProjectsscm-hunter-analysisvenvlibsite-packagesstemcontrol.py", line 1112, in authenticate
stem.connection.authenticate(self, *args, **kwargs)
File "C:UsersShaunPycharmProjectsscm-hunter-analysisvenvlibsite-packagesstemconnection.py", line 629, in authenticate
raise auth_exc
File "C:UsersShaunPycharmProjectsscm-hunter-analysisvenvlibsite-packagesstemconnection.py", line 591, in authenticate
authenticate_safecookie(controller, cookie_path, False)
File "C:UsersShaunPycharmProjectsscm-hunter-analysisvenvlibsite-packagesstemconnection.py", line 904, in authenticate_safecookie
cookie_data = _read_cookie(cookie_path, True)
File "C:UsersShaunPycharmProjectsscm-hunter-analysisvenvlibsite-packagesstemconnection.py", line 1085, in _read_cookie
raise UnreadableCookieFile(exc_msg, cookie_path, is_safecookie)
stem.connection.UnreadableCookieFile: Authentication failed: '/run/tor/control.authcookie' doesn't exist

为什么不能使用stem进行身份验证?这个错误信息让我很困惑,因为我不知道运行目录在哪里。

我尝试设置CookieAuthentication 0,重新启动服务,然后重置CookieAuthentication 1并重新启动。它会产生相同的错误。

这对我有用,首先生成一个密码(例如welcome))和hash:

$ tor --hash-password welcome
Feb 14 11:31:48.321 [warn] Tor was compiled with zstd 1.4.5, but is running with zstd 1.4.4. For safety, we'll avoid using advanced zstd functionality.
16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016
然后进入/etc/tor/torrc, uncommenthashhedcontrolpassword设置并复制上一步生成的散列:
HashedControlPassword 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016

然后重新启动service:

$ sudo service tor restart

最后一步,输入新密码欢迎在控制器认证方法中:

from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate("welcome")
controller.signal(Signal.NEWNYM)

然后确保它有效:

import requests
proxies = {'http':  'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
print("first IP:", requests.get('https://ident.me', proxies=proxies).text)
with Controller.from_port(port = 9051) as controller:
controller.authenticate("welcome")
controller.signal(Signal.NEWNYM)

print("second IP:", requests.get('https://ident.me', proxies=proxies).text)

最新更新