title: Trouble authenticating Tor with python
body: <p>Probably doing something very silly here, but I'm having some trouble authenticating automatically through Tor.</p>
  
  <p>I'm using 32 bit ubuntu 12.04 with obfuscated bridges.</p>
  
  <p>This should be all the relevant code, but let me know if there's something else that would be useful in debugging this issue:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Whenever I run this I get the following error:</p>
  
  <pre><code>515 Authentication failed: Password did not match HashedControlPassword value from configuration. Maybe you tried a plain text password
  </code></pre>
  
  <p>I tried using the --hash-password option and pasting that in the place of the AUTHENTICATE string, but that just caused the script to hang. Thoughts?</p>