I'm new to python and bencoding. I need to read and write torrent files for my project using python. I have already imported the module and here's my code to parse the torrent:
Here's the link to my module http://paste2.org/p/1442120 which is a mod of http://pypi.python.org/pypi/BitTorrent-bencode/5.0.8.1
import sys
from bencode import *
f = open('file.torrent','rb') #binary read write
for line in f:
print line,
print bdecode(line)
This throws invalid bencoded string error If I understand correctly, the bdecode function needs one value at a time but how do I parse the torrent file? or ...
The problem is that Bencoded files are not line oriented files. What you're doing is like taking a report, putting it through the shredder, and handing it to your boss one shred at a time. Here is the correct way to decode a Bencoded file:
import bencode
print bencode.bdecode(open('file.torrent', 'rb').read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With