Reputation: 1
I want to write a python torrent client (because I need it and I want to improve my skills). I have to send a HTTP get request to the tracker. I'm using the requests library.
from read_torrent import *
import requests as req
txt = read_torrent('arch.torrent')
(res, other) = parse(txt)
pl = {}
pl['uploaded'] = 0
pl['downloaded'] = 0
pl['event'] = 'started'
pl['peer_id'] = '12345678987654321234'
pl['info_hash'] = dont_know
pl['left'] = 0
pl['port'] = 6881
r = requests.get(res['announce'], params=pl)
r.raise_for_status()
print('-------RESULT-------')
print(r.text)
Two questions:
get
function in the right way?info_hash
?Ps. I've already read THIS and the wiki theory page.
Upvotes: 0
Views: 1766
Reputation: 2534
The info_hash is a SHA1 hash which you compute from the .torrent file. (bencoded info dictionary). An example for Python can be found here.
The get request should contain at first the link of the HTTP-Tracker + structure for the announce request.
Please note: most trackers are nowadays UDP (less overhead). You must make sure that your .torrent file contains a HTTP-tracker (open the file in an editor). Trackers starting with udp:// will not give you a response to your HTTP-request.
Upvotes: 1