JohnDoee / deluge-client

A very lightweight pure-python Deluge RPC Client
MIT License
87 stars 14 forks source link

deluge_client.client.TypeError: argument of type 'bool' is not iterable #17

Closed jerblack closed 6 years ago

jerblack commented 6 years ago

Hi, I'm trying to use your deluge_client and I'm running into an issue with core.get_torrents_status.

Whenever I pass in a filter_dict where one of the values contains non-string data, I get an error about that data type not being iterable. Here's my code:

def get_torrents(self):
  filter_dict = {b'state': b'Seeding', b'is_finished': True}
  keys = ['paused', 'save_path', 'name', 'num_files', 'state', 'is_finished', 'paused', 'eta', 'progress', 'files']
  return self.client.call('core.get_torrents_status', filter_dict, keys)

This results in the message below. If I remove is_finished the error goes away.

Traceback (most recent call last):
  File "/home/jeremy/deluge_mgr/deluge_mgr.py", line 118, in <module>
    t = d.get_torrents()
  File "/home/jeremy/deluge_mgr/deluge_mgr.py", line 77, in get_torrents
    return self.client.call('core.get_torrents_status', filter_dict, keys)
  File "/home/jeremy/.local/lib/python3.6/site-packages/deluge_client/client.py", line 197, in call
    return self._receive_response(self.deluge_version)
  File "/home/jeremy/.local/lib/python3.6/site-packages/deluge_client/client.py", line 176, in _receive_response
    raise exception(exception_msg)
deluge_client.client.TypeError: argument of type 'bool' is not iterable
  File "/usr/lib/python2.7/dist-packages/deluge/core/rpcserver.py", line 301, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/deluge/core/core.py", line 461, in get_torrents_status
    torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict)
  File "/usr/lib/python2.7/dist-packages/deluge/core/filtermanager.py", line 172, in filter_torrent_ids
    if field in status and status[field] in values:

If I change to using a key with a float value, the error changes again.

filter_dict = {b'state': b'Seeding', b'progress': 100.0}
...
Traceback (most recent call last):
  File "/home/jeremy/deluge_mgr/deluge_mgr.py", line 118, in <module>
    t = d.get_torrents()
  File "/home/jeremy/deluge_mgr/deluge_mgr.py", line 77, in get_torrents
    return self.client.call('core.get_torrents_status', filter_dict, keys)
  File "/home/jeremy/.local/lib/python3.6/site-packages/deluge_client/client.py", line 197, in call
    return self._receive_response(self.deluge_version)
  File "/home/jeremy/.local/lib/python3.6/site-packages/deluge_client/client.py", line 176, in _receive_response
    raise exception(exception_msg)
deluge_client.client.TypeError: argument of type 'float' is not iterable
  File "/usr/lib/python2.7/dist-packages/deluge/core/rpcserver.py", line 301, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/deluge/core/core.py", line 461, in get_torrents_status
    torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict)
  File "/usr/lib/python2.7/dist-packages/deluge/core/filtermanager.py", line 172, in filter_torrent_ids
    if field in status and status[field] in values:

Any ideas? Thanks.

JohnDoee commented 6 years ago

The best way to solve Deluge issues is to check out the Deluge code.

If we look at the code causing the error https://github.com/deluge-torrent/deluge/blob/develop/deluge/core/filtermanager.py#L178-L179 then we can see that deluge seems to expect the value in the filter_dict to be an iterable. Even going so far to call it values instead of value

So, the answer is probably something like

{b'state': [b'Seeding'], b'progress': [100.0]}
jerblack commented 6 years ago

Awesome. Thank you.