我在这里找到了 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 文件中是否有新内容。我错过了什么?不做?
原谅我的无知。我真的在这里不知所措。
最佳答案
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/