1

アナウンス要求に対する応答を解析して、トラッカーからトレントのピア リストを取得しようとしています。これは私が得た距離です:

import sys,binascii,urllib.parse,urllib.request
from bcode import bdecode

def announce(inputurl):
    with urllib.request.urlopen(inputurl) as url:
        print(url.read())
        decoded = bdecode(url.read())
        print(decoded)

infohash = sys.argv[1] # Read info hash from command line

encoded_infohash = urllib.parse.quote(binascii.a2b_hex(infohash)) # Encode inf_hash
announce_url = "http://my_tracker_ip:6969/announce?info_hash=" + encoded_infohash
announce(announce_url)

サンプル torrent の info_hash に対して実行すると、次のエラーが発生します。

b'd8:completei1e10:downloadedi2e10:incompletei3e8:intervali1698e12:min intervali849e5:peers24:\x89?GZ\xc4\x0f\xb8K\xd5r\xc4\x0f\xc0\xa8\x00\t\x00\x00\xc0\xa8\x00\x01\xe8\x8ce'
Traceback (most recent call last):
  File "announce.py", line 15, in <module>
    announce(announce_url)
  File "announce.py", line 7, in announce
    decoded = bdecode(url.read())
  File "/usr/lib/python3.4/site-packages/bcode.py", line 55, in bdecode
    if input[0] == 'i':
IndexError: index out of range

どこが間違っているのかわかりません。私はPython 3.4.3を使用しています

4

0 に答える 0