我试图通过将响应解析为announce 请求来从我的跟踪器中获取种子的对等列表。这是我已经走了多远:
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)
当我为示例种子的 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