3

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

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

(在这里说:在哪里可以找到 BitTorrent 源代码?它是 3.x 版)

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

如果您想尝试下载源代码,可以尝试运行btdownloadcurses.pybtdownloadheadless.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 文件中是否有新内容。我错过了什么?不干吗?

原谅我的无知。我在这里真的很茫然。

4

1 回答 1

1

Bram 针对旧版本的 Python 工作,其中urllib2代码没有向对象添加.msg.code属性。addinfourl具体来说,他开发的 Python 版本没有应用此更改

解决方法是自己从原始文件中找到的类中的原始addinfourl对象中复制这些属性:HTTPContentEncodingHandlerzurllib.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
于 2013-07-15T13:13:36.030 回答