运行Bram Cohen的原始BitTorrent源码(Python)

时间:2013-07-15 12:19:19

标签: python macos urllib2 bittorrent

我在这里找到了Bram Cohen的原始BitTorrent的旧资料来源:

http://bittorrent.cvs.sourceforge.net/viewvc/bittorrent/?hideattic=0

(在这里说:Where to find BitTorrent source code?它的版本是3.x)

我尝试在Mac上运行它(10.7),我的Python版本是2.7

如果您尝试下载源代码,可以尝试运行 btdownloadcurses.py btdownloadheadless.py

我试过跑:

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

好的,我会更具体。这就是我所做的:

$ ./btdownloadcurses.py --url http://torcache.net/torrent/848A6A0EC6C85507B8370E979B133214E5B5A6D4.torrent

这就是我得到的:

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

当我搜索AttributeError时,我来到了:

http://mail.python.org/pipermail/python-bugs-list/2005-May/028824.html

我认为第二条评论与我的问题有关。但我不知道从那里开始怎么做。我只是传递错误的网址吗?它与Python版本有关吗?或者BitTorrent来源很老。或者目前的.torrent文件中有新的东西。我错过了什么?没做?

原谅我的无知。我真的很茫然。

1 个答案:

答案 0 :(得分:1)

Bram使用旧版本的Python,其中urllib2代码未将.msg.code属性添加到addinfourl个对象。具体来说,他开发的Python版本没有this change applied

解决方法是自己从原始addinfourl文件中找到的HTTPContentEncodingHandler类中的原始zurllib.py对象复制这些属性:

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("Accept-Encoding","gzip")
        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: 
             pprint.pprint(headers.dict)
        url = fp.url
        resp = addinfourldecompress(fp, headers, url)
        resp.code = fp.code
        resp.msg = fp.msg
        return resp