jsonrpc Package¶
jsonrpc Package¶
exceptions Module¶
-
exception
jsonrpc.exceptions.JSONRPCDispatchException(code=None, message=None, data=None, *args, **kwargs)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCExceptionJSON-RPC Dispatch Exception.
Should be thrown in dispatch methods.
-
class
jsonrpc.exceptions.JSONRPCError(code=None, message=None, data=None)[source]¶ Bases:
objectError for JSON-RPC communication.
When a rpc call encounters an error, the Response Object MUST contain the error member with a value that is a Object with the following members:
Parameters: - code (int) – A Number that indicates the error type that occurred. This MUST be an integer.
- message (str) – A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.
- data (None or int or str or dict or list) – A Primitive or Structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
The error codes from and including -32768 to -32000 are reserved for pre-defined errors. Any code within this range, but not defined explicitly below is reserved for future use. The error codes are nearly the same as those suggested for XML-RPC at the following url: http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
-
code¶
-
data¶
-
static
deserialize(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)¶ Deserialize
s(astrorunicodeinstance containing a JSON document) to a Python object.If
sis astrinstance and is encoded with an ASCII based encoding other than utf-8 (e.g. latin-1) then an appropriateencodingname must be specified. Encodings that are not ASCII based (such as UCS-2) are not allowed and should be decoded tounicodefirst.object_hookis an optional function that will be called with the result of any object literal decode (adict). The return value ofobject_hookwill be used instead of thedict. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).object_pairs_hookis an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value ofobject_pairs_hookwill be used instead of thedict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict will remember the order of insertion). Ifobject_hookis also defined, theobject_pairs_hooktakes priority.parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN, null, true, false. This can be used to raise an exception if invalid JSON numbers are encountered.To use a custom
JSONDecodersubclass, specify it with theclskwarg; otherwiseJSONDecoderis used.
-
classmethod
from_json(json_str)¶
-
json¶
-
message¶
-
static
serialize(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, sort_keys=False, **kw)¶ Serialize
objto a JSON formattedstr.If
skipkeysis true thendictkeys that are not basic types (str,unicode,int,long,float,bool,None) will be skipped instead of raising aTypeError.If
ensure_asciiis false, all non-ASCII characters are not escaped, and the return value may be aunicodeinstance. Seedumpfor details.If
check_circularis false, then the circular reference check for container types will be skipped and a circular reference will result in anOverflowError(or worse).If
allow_nanis false, then it will be aValueErrorto serialize out of rangefloatvalues (nan,inf,-inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN,Infinity,-Infinity).If
indentis a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines.Noneis the most compact representation. Since the default item separator is', ', the output might include trailing whitespace whenindentis specified. You can useseparators=(',', ': ')to avoid this.If
separatorsis an(item_separator, dict_separator)tuple then it will be used instead of the default(', ', ': ')separators.(',', ':')is the most compact JSON representation.encodingis the character encoding for str instances, default is UTF-8.default(obj)is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.If sort_keys is
True(default:False), then the output of dictionaries will be sorted by key.To use a custom
JSONEncodersubclass (e.g. one that overrides the.default()method to serialize additional types), specify it with theclskwarg; otherwiseJSONEncoderis used.
-
exception
jsonrpc.exceptions.JSONRPCException[source]¶ Bases:
exceptions.ExceptionJSON-RPC Exception.
-
class
jsonrpc.exceptions.JSONRPCInternalError(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorInternal error.
Internal JSON-RPC error.
-
CODE= -32603¶
-
MESSAGE= 'Internal error'¶
-
-
class
jsonrpc.exceptions.JSONRPCInvalidParams(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorInvalid params.
Invalid method parameter(s).
-
CODE= -32602¶
-
MESSAGE= 'Invalid params'¶
-
-
class
jsonrpc.exceptions.JSONRPCInvalidRequest(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorInvalid Request.
The JSON sent is not a valid Request object.
-
CODE= -32600¶
-
MESSAGE= 'Invalid Request'¶
-
-
exception
jsonrpc.exceptions.JSONRPCInvalidRequestException[source]¶ Bases:
jsonrpc.exceptions.JSONRPCExceptionRequest is not valid.
-
class
jsonrpc.exceptions.JSONRPCMethodNotFound(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorMethod not found.
The method does not exist / is not available.
-
CODE= -32601¶
-
MESSAGE= 'Method not found'¶
-
-
class
jsonrpc.exceptions.JSONRPCParseError(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorParse Error.
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
-
CODE= -32700¶
-
MESSAGE= 'Parse error'¶
-
-
class
jsonrpc.exceptions.JSONRPCServerError(code=None, message=None, data=None)[source]¶ Bases:
jsonrpc.exceptions.JSONRPCErrorServer error.
Reserved for implementation-defined server-errors.
-
CODE= -32000¶
-
MESSAGE= 'Server error'¶
-
jsonrpc Module¶
JSON-RPC wrappers for version 1.0 and 2.0.
Objects diring init operation try to choose JSON-RPC 2.0 and in case of error JSON-RPC 1.0. from_json methods could decide what format is it by presence of ‘jsonrpc’ attribute.