gallexis / PyTorrent

Simple BitTorrent client made in Python - Use for learning
The Unlicense
316 stars 85 forks source link

TypeError: 'int' object is not subscriptable #11

Closed MrBruz closed 3 years ago

MrBruz commented 3 years ago
DEBUG:root:[['http://openbittorrent.com:80/announce']]
DEBUG:root:[{'path': 'README.txt', 'length': 64}]
INFO:root:PeersManager Started
INFO:root:PiecesManager Started
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): openbittorrent.com:80
DEBUG:urllib3.connectionpool:http://openbittorrent.com:80 "GET /announce?info_hash=0b%87%7B%B5%DA%C7%F4%8A%0E%A7%C4%14%8FV%5Cd%86j%C7&peer_id=%A95%C3%CE%03%A0%C8Q%D6%83%D5S%60%89O%DB%BC%96%EF%06&uploaded=0&downloaded=0&port=6881&left=64&event=started HTTP/1.1" 301 185
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): tracker.openbittorrent.com:80
DEBUG:urllib3.connectionpool:http://tracker.openbittorrent.com:80 "GET /announce?info_hash=0b%87%7B%B5%DA%C7%F4%8A%0E%A7%C4%14%8FV%5Cd%86j%C7&peer_id=%A95%C3%CE%03%A0%C8Q%D6%83%D5S%60%89O%DB%BC%96%EF%06&uploaded=0&downloaded=0&port=6881&left=64&event=started HTTP/1.1" 200 105
DEBUG: {'complete': 1, 'downloaded': 0, 'incomplete': 1, 'interval': 1752, 'min interval': 876, 'peers': b'\xb4\x94i\xd1\x1a\xe1\xb4\x94i\xd1\xc8\xd5'}
ERROR:root:HTTP scraping failed: 'int' object is not subscriptable
Traceback (most recent call last):
  File "C:\Users\Jimmy\Documents\pytorrent-master\tracker.py", line 95, in http_scraper
    s = SockAddr(p['ip'], p['port'])
TypeError: 'int' object is not subscriptable
MrBruz commented 3 years ago

image I was bored so I made a custom patch

            answer_tracker = requests.get(tracker, params=params, timeout=5)
            list_peers = bdecode(answer_tracker.content)
            if type(list_peers['peers']) is bytes:
                decodedPeersList = list_peers['peers'].hex()
                decodedPeersList2 = [decodedPeersList[i:i+12] for i in range(0, len(decodedPeersList), 12)]
                for x in decodedPeersList2:
                    ip = str(int(x[0:2], 16)) + "." + str(int(x[2:4], 16)) + "." + str(int(x[4:6], 16)) + "." + str(int(x[6:8], 16))
                    port = str(int(x[8:10], 16)) + str(int(x[10:12], 16))
                    #print("IP: " + ip +" PORT: " + port)
                    s = SockAddr(ip , port)                
                    self.dict_sock_addr[s.__hash__()] = s
            else:
                for p in list_peers['peers']:
                        s = SockAddr(p['ip'], p['port'])                
                        self.dict_sock_addr[s.__hash__()] = s

Patch starts at about line of line 89 of tracker.py

I'd recommend you merge this code with the main repo although make sure to test first @gallexis @FrozenFighter