Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#17083 closed defect (fixed)

Downloading server descriptors crashes with a TypeError

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

Description

The crash happens randomly, it must be tested multiple times until it appears.

from stem.descriptor.remote import DescriptorDownloader

downloader = DescriptorDownloader(use_mirrors=True, timeout=120, retries=1,
                                  block=True)
downloader.get_server_descriptors().run()
Traceback (most recent call last):
  File "E:\dev\prs\main\tortest.py", line 5, in <module>
    downloader.get_server_descriptors().run()
  File "e:\dev\envs\py34_x86\Python\lib\site-packages\stem\descriptor\remote.py", line 293, in run
    return list(self._run(suppress))
  File "e:\dev\envs\py34_x86\Python\lib\site-packages\stem\descriptor\remote.py", line 304, in _run
    raise self.error
  File "e:\dev\envs\py34_x86\Python\lib\site-packages\stem\descriptor\remote.py", line 357, in _download_descriptors
    self.download_url = self._pick_url(use_authority)
  File "e:\dev\envs\py34_x86\Python\lib\site-packages\stem\descriptor\remote.py", line 347, in _pick_url
    authority = random.choice(filter(HAS_V3IDENT, get_authorities().values()))
  File "e:\dev\envs\py34_x86\Python\lib\random.py", line 253, in choice
    i = self._randbelow(len(seq))
TypeError: object of type 'filter' has no len()

Child Tickets

Change History (2)

comment:1 Changed 2 years ago by atagar

Resolution: fixed
Status: newclosed

Great catch! This looks to be a difference in how python2 and python3 behaves...

Python 2.7:

>>> foo = filter(lambda x: x % 2 == 0, [1, 2, 3])
>>> foo
[2]
>>> type(foo)
<type 'list'>

Python 3.2:

>>> foo = filter(lambda x: x % 2 == 0, [1, 2, 3])
>>> foo
<filter object at 0xb6fd280c>
>>> type(foo)
<class 'filter'>

Pushed a fix, feel free to reopen if that doesn't do the trick.

comment:2 Changed 2 years ago by trodun

Works well, thanks a lot for the quick fix. \o/

Note: See TracTickets for help on using tickets.