def __send_request(self, post_data):
"""Send RPC POST request to daemon
post_data: Any valid RPC request as JSON string
If applicable, returns response['arguments']['torrents'] or
response['arguments'], otherwise response.
Raises ClientError.
"""
try:
answer = await self.__post(post_data)
except OSError as e:
log.debug('Caught OSError: %r', e)
raise ConnectionError(str(self.url))
except asyncio.TimeoutError as e:
log.debug('Caught TimeoutError: %r', e)
raise ConnectionError('Timeout after {}s: {}'.format(self.timeout, self.url))
else:
if answer['result'] != 'success':
raise RPCError(answer['result'].capitalize())
else:
if 'arguments' in answer:
if 'torrents' in answer['arguments']:
return answer['arguments']['torrents']
else:
return answer['arguments']
return answer
评论列表
文章目录