JohnDoee / autotorrent

Matches torrents with files and gets them seeded
MIT License
269 stars 34 forks source link

Fails to add torrent through transmission in python3 #9

Closed flaviut closed 8 years ago

flaviut commented 8 years ago
DEBUG:autotorrent.clients.transmission:Calling 'torrent-add' args {'download-dir': '/var/lib/transmission/Downloads', 'paused': True, 'metainfo': b'<snip>'}
Traceback (most recent call last):
  File "/home/user/tmp/autotorrent/autotorrent-env/bin/autotorrent", line 11, in <module>
    sys.exit(commandline_handler())
  File "/home/user/tmp/autotorrent/autotorrent-env/lib/python3.5/site-packages/autotorrent/cmd.py", line 127, in commandline_handler
    result = at.handle_torrentfile(os.path.join(current_path, torrent), dry_run)
  File "/home/user/tmp/autotorrent/autotorrent-env/lib/python3.5/site-packages/autotorrent/at.py", line 454, in handle_torrentfile
    if self.client.add_torrent(torrent, destination_path, files['files'], fast_resume):
  File "/home/user/tmp/autotorrent/autotorrent-env/lib/python3.5/site-packages/autotorrent/clients/transmission.py", line 98, in add_torrent
    result = self.call('torrent-add', **kwargs)
  File "/home/user/tmp/autotorrent/autotorrent-env/lib/python3.5/site-packages/autotorrent/clients/transmission.py", line 46, in call
    r = self._call(method, **kwargs)
  File "/home/user/tmp/autotorrent/autotorrent-env/lib/python3.5/site-packages/autotorrent/clients/transmission.py", line 38, in _call
    result = requests.post(self.url, data=json.dumps({'method': method, 'arguments': kwargs}), headers={'X-Transmission-Session-Id': self._session_id})
  File "/usr/lib64/python3.5/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python3.5/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python3.5/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python3.5/json/encoder.py", line 180, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'<snip>' is not JSON serializable

The solution is to change lib/python3.5/site-packages/autotorrent/clients/transmission.py: encoded_torrent -> encoded_torrent.decode('utf-8') and name -> name.decode('utf-8')

Not sure how that change will work with python2.

JohnDoee commented 8 years ago

Your fix did the trick and is compatible with Python 2, so all is good. Thanks!