可能在这里做一些非常愚蠢的事情,但我在通过Tor自动验证时遇到了麻烦。
我正在使用带有模糊桥接器的32位ubuntu 12.04。
这应该是所有相关的代码,但请告诉我是否还有其他方法可用于调试此问题:
import socket
import socks
import httplib
def connectTor():
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True)
#9050 is the Tor proxy port
socket.socket = socks.socksocket
def newIdentity():
socks.setdefaultproxy() #Disconnect from Tor network
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 46594))
s.send("AUTHENTICATE\r\n")
response = s.recv(128)
#128 bytes of data for now, just to see how Tor responds
print response
if response.startswith("250"): #250 is the code for a positive response from Tor
s.send("SIGNAL NEWNYM\r\n") #Use a new identity
s.close()
connectTor() #Just to make sure we're still connected to Tor
每当我运行此操作时,我都会收到以下错误:
515 Authentication failed: Password did not match HashedControlPassword value from configuration. Maybe you tried a plain text password
我尝试使用--hash-password选项并将其粘贴到AUTHENTICATE字符串的位置,但这只会导致脚本挂起。想法?
答案 0 :(得分:5)
该错误意味着您在torrc中设置了HashedControlPassword选项。我建议选择CookieAuthentication 1
,然后使用控制器库,而不是从头开始。
你在这里尝试做什么(发布一个NEWNYM)是一个非常非常常见的请求(1,2)所以我刚为它添加了FAQ entry。以下是使用stem ...
的示例from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)