borzunov / bit-torrent

πŸ“ 🌎 BitTorrent client built with Python + asyncio
MIT License
155 stars 28 forks source link

Exception in try_to_announce #1

Closed chaminaud closed 6 years ago

chaminaud commented 6 years ago

Hi I am testing your software and when I run it I get the following exception (I did enable debug mode in the Qt version to get this)

WARNING _run_once:1308 13:01:56 asyncio Executing <Task finished coro=<TorrentManager.run() done, defined at D:/Projet/bit-torrent-master\torrent_client\algorithms\torrent_manager.py:64> exception=TypeError("Invalid variable type: mapping value should be str or int, got b'\x9c\xb0a\xf6[I\xb1\x1e\xf4\xa4S:\xf1\x15\x10\x84\xbf{c\x8b'",) created at D:/Projet/bit-torrent-master\torrent_client\control\manager.py:63> took 36.281 seconds

I am running it On Windows10, in Pycharm 2017, python 3.5, and the Bitarray module come from here https://www.lfd.uci.edu/~gohlke/pythonlibs/

I start debugging but some help will be welcome

Update: b'\x9c\xb0a\xf6[I\xb1\x1e\xf4\xa4S:\xf1\x15\x10\x84\xbf{c\x8b' is the torrent hash

in tracker_client\http.py session.get() cannot convert bytes (params['info_hash'] and params['peer_id'] ) , it needs string or int.

Update2: I replace

        with aiohttp.Timeout(HTTPTrackerClient.REQUEST_TIMEOUT), aiohttp.ClientSession() as session:
             async with session.get(self._announce_url, params=params) as conn:
               response = await conn.read()

with

        import urllib.request
        import urllib.parse
        params_str = urllib.parse.urlencode(params)
        response = urllib.request.urlopen(self._announce_url + "?" + params_str).read()

To get it working aiohttp seems not doing the job correctly

borzunov commented 6 years ago

Hi @chaminaud,

Indeed, the bug was caused by a backward-incompatible change in aiohttp. I've fixed it in 59c1865020677bc32c2951464c87d3cee542feff.

Feel free to open new issues if you encounter more bugs.