I am following this post in order to find the tor exit node IP.

Running the proposed script ( see below), I get the error:

Traceback (most recent call last):
  File "/mnt/.rot//ip.py", line 6, in <module>
    for circ in controller.get_circuits():
  File "/usr/lib/python2.7/dist-packages/stem/control.py", line 414, in wrapped
    raise exc
TypeError: initial_value must be unicode or None, not

What is the origin of this error and what should be changed for this script to work?

My control port is open I can access it with telnet.

PS: full script

from stem import CircStatus
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:

  for circ in controller.get_circuits():
    if circ.status != CircStatus.BUILT:

    exit_fp, exit_nickname = circ.path[-1]

    exit_desc = controller.get_network_status(exit_fp, None)
    exit_address = exit_desc.address if exit_desc else 'unknown'

    print "Exit relay"
    print "  fingerprint: %s" % exit_fp
    print "  nickname: %s" % exit_nickname
    print "  address: %s" % exit_address

/usr/lib/python2.7/dist-packages/stem/control.py (from which the error come from)

   409            return func(self, *args, **kwargs)
   410          except Exception as exc:
   411            default = get_default(func, args, kwargs)
   413            if default == UNDEFINED:
   414              raise exc
   415            else:
   416              return default
   417      else:
   418        @functools.wraps(func)
   419        def wrapped(self, *args, **kwargs):
  • Pretty sure what you've given us isn't an accurate representation of your script since the line numbers don't match. – cacahuatl Nov 15 '16 at 20:27
  • Can you have a brief look at new file where the error is originating. Thank you. – user15070 Nov 16 '16 at 2:17

I simply reinstalled stem from the git repository to solve the issue.

The previous installation was realized with

# apt-get install python-stem

on Debian 4.6.4-1kali1 (2016-07-21). Another package may have been forgotten.

  • lol kali linux skiddies :D – cacahuatl Nov 16 '16 at 21:33

You have your system settings wrong, pehaps: it works like a copy-and-paste for me:

# python -V
Python 2.7.9

# python getexit.py
Exit relay

nickname: nickname-scrubbled
Exit relay
nickname: nickname2-scrubbled

Are you sure you're using the latest Stem library? Mine is:

 # pip list | grep stem
 stem (1.4.0)
  • My version is Python 2.7.12+ – user15070 Nov 16 '16 at 2:06
  • and the stem library? do you use a non-english locale in your linux/unix account? – Alexey Vesnin Nov 16 '16 at 2:08
  • I found a substitute command: echo -e 'AUTHENTICATE "p"\r\nsignal\ngetinfo circuit-status\r\nQUIT' | nc 9051 – user15070 Nov 16 '16 at 14:50
  • yes, but it's a shellscript(that I actually, prefer). The problem is, that your Python may have a problem that will appear not just there. Try to set LC_ALL to en_US.UTF-8 like in this tutorial and try it – Alexey Vesnin Nov 16 '16 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy