I have the following code:
with Controller.from_port(port = 9151) as controller:
controller.authenticate()
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9150)
socket.socket = socks.socksocket
controller.signal(Signal.NEWNYM)
url= "https://www.example.com"
browser = mechanize.Browser()
text = browser.open(url).read()
When I run it I get the following lengthy traceback:
Traceback (most recent call last):
File "C:\Users\HOJU\Desktop\edp\gog.py", line 168, in <module>
main()
File "C:\Users\HOJU\Desktop\edp\gog.py", line 101, in main
text = browser.open(url).read()
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 203, in ope
n
return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 230, in _me
ch_open
response = UserAgentBase.open(self, request, data)
File "C:\Python27\lib\site-packages\mechanize\_opener.py", line 193, in open
response = urlopen(self, req, data)
File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 344, in
_open
'_open', req)
File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 332, in
_call_chain
result = func(*args)
File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 1170, in
https_open
return self.do_open(conn_factory, req)
File "C:\Python27\lib\site-packages\mechanize\_urllib2_fork.py", line 1115, in
do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python27\lib\httplib.py", line 946, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 987, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 940, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 803, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 755, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1152, in connect
self.timeout, self.source_address)
File "C:\Users\HOJU\Desktop\edp\gog.py", line 32, in create_connection
sock.connect(address)
File "C:\Python27\lib\site-packages\socks.py", line 392, in connect
self.__negotiatesocks5(destpair[0],destpair[1])
File "C:\Python27\lib\site-packages\socks.py", line 199, in __negotiatesocks5
self.sendall("\x05\x01\x00")
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 165, in sendall
socket.socket.sendall(self, bytes)
File "C:\Python27\lib\site-packages\socks.py", line 163, in sendall
if 'encode' in dir(bytes):
RuntimeError: maximum recursion depth exceeded while calling a Python object
How can I fix this?