2626
2727- HTTP connections persist for the life of the AuthServiceProxy object
2828 (if server supports HTTP/1.1)
29- - sends protocol 'version' , per JSON-RPC 1.1
29+ - sends "jsonrpc":"2.0" , per JSON-RPC 2.0
3030- sends proper, incrementing 'id'
3131- sends Basic HTTP authentication headers
3232- parses all JSON numbers that look like floats as Decimal
@@ -117,23 +117,36 @@ def get_request(self, *args, **argsn):
117117 params = dict (args = args , ** argsn )
118118 else :
119119 params = args or argsn
120- return {'version ' : '1.1 ' ,
120+ return {'jsonrpc ' : '2.0 ' ,
121121 'method' : self ._service_name ,
122122 'params' : params ,
123123 'id' : AuthServiceProxy .__id_count }
124124
125125 def __call__ (self , * args , ** argsn ):
126126 postdata = json .dumps (self .get_request (* args , ** argsn ), default = serialization_fallback , ensure_ascii = self .ensure_ascii )
127127 response , status = self ._request ('POST' , self .__url .path , postdata .encode ('utf-8' ))
128- if response ['error' ] is not None :
129- raise JSONRPCException (response ['error' ], status )
130- elif 'result' not in response :
131- raise JSONRPCException ({
132- 'code' : - 343 , 'message' : 'missing JSON-RPC result' }, status )
133- elif status != HTTPStatus .OK :
134- raise JSONRPCException ({
135- 'code' : - 342 , 'message' : 'non-200 HTTP status code but no JSON-RPC error' }, status )
128+ # For backwards compatibility tests, accept JSON RPC 1.1 responses
129+ if 'jsonrpc' not in response :
130+ if response ['error' ] is not None :
131+ raise JSONRPCException (response ['error' ], status )
132+ elif 'result' not in response :
133+ raise JSONRPCException ({
134+ 'code' : - 343 , 'message' : 'missing JSON-RPC result' }, status )
135+ elif status != HTTPStatus .OK :
136+ raise JSONRPCException ({
137+ 'code' : - 342 , 'message' : 'non-200 HTTP status code but no JSON-RPC error' }, status )
138+ else :
139+ return response ['result' ]
136140 else :
141+ assert response ['jsonrpc' ] == '2.0'
142+ if status != HTTPStatus .OK :
143+ raise JSONRPCException ({
144+ 'code' : - 342 , 'message' : 'non-200 HTTP status code' }, status )
145+ if 'error' in response :
146+ raise JSONRPCException (response ['error' ], status )
147+ elif 'result' not in response :
148+ raise JSONRPCException ({
149+ 'code' : - 343 , 'message' : 'missing JSON-RPC 2.0 result and error' }, status )
137150 return response ['result' ]
138151
139152 def batch (self , rpc_call_list ):
@@ -142,7 +155,7 @@ def batch(self, rpc_call_list):
142155 response , status = self ._request ('POST' , self .__url .path , postdata .encode ('utf-8' ))
143156 if status != HTTPStatus .OK :
144157 raise JSONRPCException ({
145- 'code' : - 342 , 'message' : 'non-200 HTTP status code but no JSON-RPC error ' }, status )
158+ 'code' : - 342 , 'message' : 'non-200 HTTP status code' }, status )
146159 return response
147160
148161 def _get_response (self ):
0 commit comments