jsonrpc module¶
JSON-RPC 常用方法
date: | 2013-12-13 |
---|---|
author: | 刘雪彦 <lxy@hesong.net> |
- exception jsonrpc.Error(id_=None, code=None, message=None, data=None)¶
基类:builtins.Exception
json rpc 的 Error Response 对象
- to_dict()¶
转为 dict
- to_json()¶
转为 JSON 字符串
- exception jsonrpc.FormatError(id_=None, code=-32700, message='Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.', data=None)¶
-
JSON-RPC格式错误
- exception jsonrpc.InvalidErrorError(id_=None, code=-32600, message='The JSON sent is not a valid Error object.', data=None)¶
-
无效的JSON-RPC错误回复
- exception jsonrpc.InvalidParamsError(id_=None, code=-32602, message='Invalid method parameter(s).', data=None)¶
-
无效的JSON-RPC请求参数
- exception jsonrpc.InvalidRequestError(id_=None, code=-32600, message='The JSON sent is not a valid Request object.', data=None)¶
-
无效的JSON-RPC请求
- exception jsonrpc.InvalidResponseError(id_=None, code=-32600, message='The JSON sent is not a valid Response object.', data=None)¶
-
无效的JSON-RPC回复
- exception jsonrpc.MethodNotFoundError(id_=None, code=-32601, message='The method does not exist / is not available.', data=None)¶
-
JSON-RPC请求方法未找到
- exception jsonrpc.RpcTimeoutError¶
基类:builtins.Exception
- jsonrpc.parse(txt)¶
解析 JSON RPC
参数: txt – 带解析的 JSON 字符串 返回: request, result, error 如果是request,第一个参数返回该请求的dict,格式是: {'id': 'id-of-the-request', 'method': 'your_method', params['what', 'ever', 'params']}
其它两个参数是 None
如果是返回结果,第二个参数返回结果 dict,格式是:
{'id': 'id-of-the-request', 'result': 'your_result'}
其它两个参数是 None
- jsonrpc.recursive_jsonable(obj, encoding='utf-8')¶
递归转为可JSON序列化数据类型
参数: - obj – 要转化的对象,可以是基本数据类型,或者 dict, list, tuple, date, datetime
- encoding – 编码,默认是utf8
返回: 转换后对象
- jsonrpc.to_bytes(s, encoding='utf-8')¶
- jsonrpc.to_str(s, encoding='utf-8')¶
- jsonrpc.to_unicode(s, encoding='utf-8')¶