刚刚开始接触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.jpgimport 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.jpgTraceback (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中一行一行运行,看起来原因也是编码出现了问题。