joalT joalT - 1 year ago 73
Python Question

Running Bram Cohen's original BitTorrent sources (Python)

I found an old source of Bram Cohen's original BitTorrent here:

(says here: bittorrent source code? that it's version 3.x)

and I'm trying to run it on my Mac (10.7) and my Python version is 2.7

If you would try and download the source, you can try running the or the

I tried running:

$ ./ --url http://sometorrenthost/somefile.torrent

Ok, I'll be more specific. This is what I did:

$ ./ --url

And this is what I got:

Traceback (most recent call last):
File "./", line 243, in <module>
run(mainerrlist, argv[1:])
File "./", line 186, in run
download(params, d.chooseFile, d.display, d.finished, d.error, mainkillflag, fieldw)
File "/Users/joal21/Desktop/BitTorrent/BitTorrent/", line 120, in download
h = urlopen(config['url'])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 127, in urlopen
return, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 410, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 517, in http_response
code, msg, hdrs = response.code, response.msg,
AttributeError: addinfourldecompress instance has no attribute 'msg'

When I searched for that
, I came to:

I think the second comment has something to do with my problem. But I don't know how else to procees from there. Am I simply just passing the wrong url? Does it have something to do with the Python version? Or of the BitTorrent source being old. Or is there something new in present .torrent files. What am I missing? Not doing?

Forgive my ignorance. I'm really at a loss here.

Answer Source

Bram worked against an older version of Python, one where the urllib2 code did not add .msg and .code attributes to addinfourl objects. Specifically, the Python version he developed with did not have this change applied.

The workaround is to copy those attributes yourself from the original addinfourl object in the HTTPContentEncodingHandler class found in the original file:

class HTTPContentEncodingHandler(HTTPHandler):
    """Inherit and add gzip/deflate/etc support to HTTP gets."""
    def http_open(self, req):
        # add the Accept-Encoding header to the request
        # support gzip encoding (identity is assumed)
        req.add_header('User-Agent', 'BitTorrent/' + version)
        if DEBUG: 
            print "Sending:" 
            print req.headers
            print "\n"
        fp = HTTPHandler.http_open(self,req)
        headers = fp.headers
        if DEBUG: 
        url = fp.url
        resp = addinfourldecompress(fp, headers, url)
        resp.code = fp.code
        resp.msg = fp.msg
        return resp
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download