1
votes

I am trying to control tor on ubuntu linux using python's stem library as instructed on tor's website. However, when I ran the suggested python code

from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
    controller.authenticate()  # provide the password here if you set one

    bytes_read = controller.get_info("traffic/read")

    bytes_written = controller.get_info("traffic/written")

    print "My Tor relay has read %s bytes and written %s." % (bytes_read, bytes_written)

I get the error:

Traceback (most recent call last):

File "littleRelay.py", line 5, in module

bytes_read = controller.get_info("traffic/read")

File "/usr/local/lib/python2.7/dist-packages/stem/control.py", line 852, in get_info

raise exc

stem.InvalidArguments: GETINFO request contained unrecognized keywords: traffic/read

So how can I get Tor relay info via python+stem on linux? I think Tor is running fine because I started tor from the terminal and it says

[notice] Tor has successfully opened a circuit. Looks like client functionality is working.

[notice] Bootstrapped 100%: Done.

Furthermore, when I run the above python code, the terminal says

[notice] New control connection opened.

P.S. I have also tried the code on a windows pc and it worked. I'm really puzzled now.

2
That didn't work but thanks Andre.user3478516

2 Answers

3
votes

That error indicates that Tor doesn't support the 'GETINFO traffic/read' query. This is odd - that is a feature I added to Tor back in 2011. Perhaps your copy of Tor is very, very out of date?

0
votes

Problem Solved! Thank you Damian!

I uninstalled Tor on Ubuntu and install Tor again by following the detail guideline here. Now Tor works with the python code.

I'm not sure how exactly the problem arose but I suppose the problem had to do with installing Tor on Ubuntu by naively using

sudo apt-get install tor