I'm writing a script in python.
My script uses urllib2 to read web pages.
I'm using Socksipy to force urllib2 to use socks proxy (TOR).
My problem is after setting socket.socket
TorCtl doesn't work and raises exception.
the code that doesn't work is (first newTorId()
works and second fails!):
newTorId() #This works
import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "localhost", 9050)
socket.socket = socks.socksocket
newTorId() #this Fails!
newTorId
is defined as this:
from TorCtl import TorCtl
def newTorId():
conn = TorCtl.connect(passphrase="test")
conn.send_signal("NEWNYM")
The exception is:
__init__() takes exactly 2 arguments (3 given)
Traceback (most recent call last):
File "script.py", line 97, in <module>
newTorId()
File "script.py", line 27, in newTorId
conn.send_signal("NEWNYM")
AttributeError: 'NoneType' object has no attribute 'send_signal'
What is the problem?