Opened 3 years ago

Closed 3 years ago

#13879 closed defect (fixed)

stem : GETINFO request contained unrecognized keywords

Reported by: toralf Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

The following code snippet worked fine so far:

import time
import functools

from stem import ORStatus, ORClosureReason
from stem.control import EventType, Controller

def main():
  print "Tracking requests for tor exits. Press 'enter' to end."
  print

  with Controller.from_port() as controller:
    controller.authenticate()

    orconn_listener = functools.partial(orconn_event, controller)
    controller.add_event_listener(orconn_listener, EventType.ORCONN)

    raw_input()  # wait for user to press enter


def orconn_event(controller, event):
  if event.status == ORStatus.CLOSED and event.reason == ORClosureReason.IOERROR:

    fingerprint = event.endpoint_fingerprint
    relay = controller.get_network_status(fingerprint)

    print " %i %s %15s %5i %s %s %s" % (event.arrived_at, time.ctime(event.arrived_at), relay.address, relay.or_port, relay.fingerprint, controller.get_info("ip-to-country/%s" % relay.address, 'unknown'), relay.nickname)

if __name__ == '__main__':
  main() 

but sometimes I do get:

tfoerste@tor-relay ~ $ sudo python /home/tfoerste/err.py 
Tracking requests for tor exits. Press 'enter' to end.

 1417547699 Tue Dec  2 20:14:59 2014  81.169.152.100  9001 A784839B4201C1C6714D441D3C0122E76BD6FF9E de 0x7ffd
Exception in thread Event Notifier:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib64/python2.7/site-packages/stem/control.py", line 775, in _event_loop
    self._handle_event(event_message)
  File "/usr/lib64/python2.7/site-packages/stem/control.py", line 2810, in _handle_event
    listener(event_message)
  File "/home/tfoerste/err.py", line 25, in orconn_event
    relay = controller.get_network_status(fingerprint)
  File "/usr/lib64/python2.7/site-packages/stem/control.py", line 1670, in get_network_status
    raise exc
InvalidArguments: GETINFO request contained unrecognized keywords: ns/id/5AC9C5AA75BA1F18D8459B326B4B8111A856D290


^CTraceback (most recent call last):
  File "/home/tfoerste/err.py", line 30, in <module>
    main() 
  File "/home/tfoerste/err.py", line 17, in main
    raw_input()  # wait for user to press enter
KeyboardInterrupt

I'm using net-libs/stem-1.2.2_p20141018 at a hardened Gentoo 64 bit with python 2.7

Child Tickets

Change History (4)

comment:1 Changed 3 years ago by atagar

Hi toralf. That's happening because your 'GETINFO ns/id/5AC9C5AA75BA1F18D8459B326B4B8111A856D290' request to Tor is getting a response that means "tor doesn't have the router status entry for this relay".

If you haven't set it, please give the following torrc entries a try...

https://stem.torproject.org/tutorials/mirror_mirror_on_the_wall.html#can-i-get-descriptors-from-the-tor-process

I suppose I could add a new exception type for NoDescriptorAvailable so the error is a bit descriptive - would you prefer that?

comment:2 Changed 3 years ago by toralf

I tried

FetchDirInfoEarly 1
FetchDirInfoExtraEarly 1
FetchUselessDescriptors 1
UseMicrodescriptors 0
DownloadExtraInfo 1

in torrc and reloaded the tor process, but still get (till now):

Unable to retrieve get_network_status from fingerprint: C8A8C8E7FA6F936C1ED0ACBAC0BD8F1D3394C181 GETINFO request contained unrecognized keywords: ns/id/C8A8C8E7FA6F936C1ED0ACBAC0BD8F1D3394C181

with this small change to my script :

    try:
      relay = controller.get_network_status(fingerprint)
      print " %i %s %15s %5i %s %s %s" % (event.arrived_at, time.ctime(event.arrived_at), relay.address, relay.or_port, fingerprint, controller.get_info("ip-to-country/%s" % relay.address, 'unknown'), relay.nickname)
    except Exception as exc:
      print "Unable to retrieve get_network_status from fingerprint: %s %s" % (fingerprint, exc)

Maybe I have to wait a little bit longer till tor has fetched all infos ?

But in general, yes, a better error explanation about missing descriptor info would be nice :-)

comment:3 Changed 3 years ago by atagar

All getter methods on the Controller object support a default value, which can make this a bit nicer...

relay = controller.get_network_status(fingerprint, None)

if relay:
  print " %i %s %15s %5i %s %s %s" % (event.arrived_at, time.ctime(event.arrived_at), relay.address, relay.or_port, fingerprint, controller.get_info("ip-to-country/%s" % relay.address, 'unknown'), relay.nickname)
else:
  print "Unable to retrieve the descriptor from tor for: %s" % fingerprint

It's kinda odd tor is emitting an ORCONN event but unable to provide its router status entry. This is a tor issue though. Feel free to file another ticket under the tor component to ask about that - for my part I'll simply be improving the error message for this ticket.

comment:4 Changed 3 years ago by atagar

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.