Code below (apologies for ugliness), I'm running this to calculate the hash for a torrent but it is giving me a different answer than when I open that torrent directly in Transmission:
I'm testing on r_000 on this page: http://gen.lib.rus.ec/repository_torrent/
Transmission gives me: 63a04291a8b266d968aa7ab8a276543fa63a9e84
My code gives me: 1882ff6534ee4aa660e2fbf225c1796638bea4c0
import bencoding
from io import BytesIO
import binascii
import hashlib
with open("cache/r_000.torrent", "rb") as f:
data = bencoding.bdecode(f.read())
info = data[b'info']
hashed_info = hashlib.sha1(info[b'pieces']).hexdigest()
print(hashed_info)
Any idea what I've screwed up? Thanks!
I made the same mistake. Searching found this question and that helped me fix it. But to make it clearer for others who come this way via searches on how to do it from python3+ this is the explicit fix:
Change:
to:
Thanks to Encombe for clarifying the info hash here: https://stackoverflow.com/questions/28140766/28162042#28162042
A full but minimalistic example is:
Result: