4

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?

unor
  • 398
  • 1
  • 19
Mustard Tiger
  • 141
  • 1
  • 3

1 Answers1

1

Here are your pyCURL and a howto

UPDATE: Copy-pasting by request - copyright to code to sources mentioned upstrings:

amnesia@amnesia: ~$ cat checkTor.py
#!/usr/bin/env python

import pycurl

curl = pycurl.Curl()
curl.setopt( pycurl.URL, 'https://check.torproject.org/' )
curl.setopt( pycurl.PROXY, '127.0.0.1' )
curl.setopt( pycurl.PROXYPORT, 9050 )
curl.setopt( pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME )

curl.perform()
amnesia@amnesia: ~$ time ./checkTor.py
<!doctype html>
...
Congratulations. This browser is configured to use Tor.
...
real 0m2.487s
user 0m0.060s
sys 0m0.000s

That is your HTTPS request via Tor, no DNS leaks. Your STEM request must not use proxy - Tor does not allow LAN IP's through SOCKS, and it's correct. You must not use any proxies sending signal NEWNYM. To capture HTML output use cURL options like RETURN_TRANSFER - see docs to fit your needs

Alexey Vesnin
  • 6,385
  • 3
  • 15
  • 36