V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
toaoman
V2EX  ›  Python

运行 aria2 官方的 xmlrpc 实例报错。

  •  
  •   toaoman · 2015-01-26 19:20:38 +08:00 · 4321 次点击
    这是一个创建于 3383 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚刚开始接触python,对于通过xml-rpc远程过程调用来控制aria2下载文件很感兴趣。刚好看到aria2的网络手册上有这么一段程序的实例,就在python2.7中运行了一下。(aria2的启动参数为: aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -c )

    http://img.bbs.csdn.net/upload/201501/26/1422260883_325696.jpg

    import xmlrpclib
    s = xmlrpclib.ServerProxy('http://localhost:6800/rpc')
    s.aria2.addTorrent(xmlrpclib.Binary(open('file.torrent').read()))

    程序运行后报错信息如下:
    http://img.bbs.csdn.net/upload/201501/26/1422261594_631892.jpg

    Traceback (most recent call last):
    File "C:\test.py", line 3, in <module>
    s.aria2.addTorrent(xmlrpclib.Binary(open('file.torrent').read()))
    File "C:\Python27\lib\xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
    File "C:\Python27\lib\xmlrpclib.py", line 1570, in __request
    verbose=self.__verbose
    File "C:\Python27\lib\xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
    File "C:\Python27\lib\xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
    File "C:\Python27\lib\xmlrpclib.py", line 1468, in parse_response
    return u.close()
    File "C:\Python27\lib\xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
    Fault: <Fault 1: 'Bencode decoding failed: Expected 16860 bytes of data, but only 39 read.'>

    看起来是编码的原因造成的,但是改了好久都搞不定,请python的高手们多指点迷津。

    后台运行的aria2c.下载地址。
    http://sourceforge.jp/projects/sfnet_aria2rpcmanager/downloads/win-releases/Aria2RPCManagerv1.0.zip/

    另外运行官方手册中的那个json-rpc的实例也会报错。
    报错信息为:
    Traceback (most recent call last):
    File "C:\test.py", line 5, in <module>
    c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq)
    File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
    File "C:\Python27\lib\urllib2.py", line 397, in open
    response = meth(req, response)
    File "C:\Python27\lib\urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
    File "C:\Python27\lib\urllib2.py", line 435, in error
    return self._call_chain(*args)
    File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
    result = func(*args)
    File "C:\Python27\lib\urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    HTTPError: HTTP Error 500: Internal Server Error

    我在ipython中一行一行运行,看起来原因也是编码出现了问题。
    1 条回复
    toaoman
        1
    toaoman  
    OP
       2015-01-27 10:06:24 +08:00
    已自行解决,请管理员删除该主题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2218 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:09 · PVG 18:09 · LAX 03:09 · JFK 06:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.