I used the ServiceProxy class as a client to a JSON-RPC server from
jsonrpclib (
https://github.com/joshmarshall/jsonrpclib). It fails
with:
Traceback (most recent call last):
File "./rpcclient.py", line 9, in <module>
print(s.reverse('foobar'))
File "/usr/lib/python2.7/site-packages/jsonrpc/proxy.py", line 44,
in __call__
if resp['error'] != None:
KeyError: 'error'
The TCP stream looks as follows:
POST /RPC2 HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 55
Host: localhost:8000
User-Agent: Python-urllib/1.17
{"params":["foobar"],"method":"reverse","id":"jsonrpc"}
HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.2
Date: Thu, 17 Nov 2011 09:36:52 GMT
Content-type: application/json-rpc
Content-length: 55
{"jsonrpc": "2.0", "result": "raboof", "id": "jsonrpc"}
According to the specification of JSON-RPC-2.0 (
http://www.jsonrpc.org/
spec.html), the error member must not exist if there was no error:
5 Response object
[...]
error
This member MUST NOT exist if there was no error triggered during
invocation.
[...]
The following patch fixes the behaviour:
--- jsonrpc/proxy.py.orig 2011-11-16 11:44:06.145643756 +0200
+++ jsonrpc/proxy.py 2011-11-16 11:45:27.198537988 +0200
@@ -41,7 +41,7 @@
postdata = dumps({"method": self.__serviceName, 'params':
args, 'id':'jsonrpc'})
respdata = urllib.urlopen(self.__serviceURL,
postdata).read()
resp = loads(respdata)
- if resp['error'] != None:
+ if 'error' in resp and resp['error'] != None:
raise JSONRPCException(resp['error'])
else:
return resp['result']
Please consider applying.
Thanks,
Chris