TOR Stem 找不到 cookie 控制认证文件
TOR Stem not finding the cookie control authentication file
我正在使用 Windows 10. 我正在使用 Tor Win32 服务 运行ning.
这是我的 torrc 文件,来自 C:...\Tor Browser\Browser\TorBrowser\Data\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:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\control.py", line 1112, in authenticate
stem.connection.authenticate(self, *args, **kwargs)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 629, in authenticate
raise auth_exc
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 591, in authenticate
authenticate_safecookie(controller, cookie_path, False)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 904, in authenticate_safecookie
cookie_data = _read_cookie(cookie_path, True)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.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)和散列:
$ 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,取消注释HashedControlPassword设置并复制上一步生成的哈希:
HashedControlPassword 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016
然后重启服务:
$ sudo service tor restart
最后一步,在控制器身份验证方法中传递您的新密码 welcome:
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)
我正在使用 Windows 10. 我正在使用 Tor Win32 服务 运行ning.
这是我的 torrc 文件,来自 C:...\Tor Browser\Browser\TorBrowser\Data\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:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\control.py", line 1112, in authenticate
stem.connection.authenticate(self, *args, **kwargs)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 629, in authenticate
raise auth_exc
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 591, in authenticate
authenticate_safecookie(controller, cookie_path, False)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.py", line 904, in authenticate_safecookie
cookie_data = _read_cookie(cookie_path, True)
File "C:\Users\Shaun\PycharmProjects\scm-hunter-analysis\venv\lib\site-packages\stem\connection.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)和散列:
$ 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,取消注释HashedControlPassword设置并复制上一步生成的哈希:
HashedControlPassword 16:05B7B9E8F3D0AB3160E030928F9517EDA5348ECD1CDCE2D95F0D230016
然后重启服务:
$ sudo service tor restart
最后一步,在控制器身份验证方法中传递您的新密码 welcome:
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)