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

标签 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.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 文件中是否有新内容。我错过了什么?不做?

原谅我的无知。我真的在这里不知所措。

最佳答案

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

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

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

关于python - 运行 Bram Cohen 的原始 BitTorrent 源 (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17654103/

相关文章:

python - 使用 urllib2 从 URL 写入 PDF 文件

ssl - 使用 urllib2 连接 sslv3 页面

python - 从 python 代码控制本地 redis 服务器

Python子模块在python 3.7中正确导入但不是3.6

python - Django INNER JOIN 使用带有 WHERE 子句的外键

swift - 错误 : Cannot convert value of type 'URL' to expected argument type 'String'

macos - 将gradle解压缩以在macosx上安装-需要与GNU兼容的解压缩

iphone - 代表似乎自动设置为零

python - 使用 HTTP 代理 - Python

Python:计算字符串中列表项的出现次数