26
26
27
27
- HTTP connections persist for the life of the AuthServiceProxy object
28
28
(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
30
30
- sends proper, incrementing 'id'
31
31
- sends Basic HTTP authentication headers
32
32
- parses all JSON numbers that look like floats as Decimal
@@ -117,23 +117,36 @@ def get_request(self, *args, **argsn):
117
117
params = dict (args = args , ** argsn )
118
118
else :
119
119
params = args or argsn
120
- return {'version ' : '1.1 ' ,
120
+ return {'jsonrpc ' : '2.0 ' ,
121
121
'method' : self ._service_name ,
122
122
'params' : params ,
123
123
'id' : AuthServiceProxy .__id_count }
124
124
125
125
def __call__ (self , * args , ** argsn ):
126
126
postdata = json .dumps (self .get_request (* args , ** argsn ), default = serialization_fallback , ensure_ascii = self .ensure_ascii )
127
127
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' ]
136
140
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 )
137
150
return response ['result' ]
138
151
139
152
def batch (self , rpc_call_list ):
@@ -142,7 +155,7 @@ def batch(self, rpc_call_list):
142
155
response , status = self ._request ('POST' , self .__url .path , postdata .encode ('utf-8' ))
143
156
if status != HTTPStatus .OK :
144
157
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 )
146
159
return response
147
160
148
161
def _get_response (self ):
0 commit comments