Python authentication error with python

Maybe something is very stupid here, but I'm having problems with automatic authentication through Tor.

I am using 32-bit ubuntu 12.04 with obfuscation bridges.

This should be all the relevant code, but let me know if there is anything else that would be helpful in debugging this problem:

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 

Whenever I run this, I get the following error:

 515 Authentication failed: Password did not match HashedControlPassword value from configuration. Maybe you tried a plain text password 

I tried using the -hash-password option and pasted it instead of the AUTHENTICATE line, but that just caused the script to hang. Thoughts?

+4
source share
1 answer

This error means that you have set the HashedControlPassword parameter in your torrc. I would suggest CookieAuthentication 1 instead, using the controller library, rather than doing it from scratch.

What you are trying to do here (NEWNYM release) is a very, very common request ( 1 , 2 ), so I just added the frequently asked questions . Here is an example using stem ...

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

All Articles