Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support talking to legacy JSON-RPC 1.0 servers #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions jsonrpclib/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def request(self, method, params=[]):
if not self.id:
self.id = random_id()
request = { 'id':self.id, 'method':method }
if params:
if params or self.version < 1.1:
request['params'] = params
if self.version >= 2:
request['jsonrpc'] = str(self.version)
Expand Down Expand Up @@ -524,9 +524,15 @@ def check_for_errors(result):
if 'result' not in result.keys() and 'error' not in result.keys():
raise ValueError('Response does not have a result or error key.')
if 'error' in result.keys() and result['error'] != None:
code = result['error']['code']
message = result['error']['message']
raise ProtocolError((code, message))
if 'code' in result['error'] and 'message' in result['error']:
code = result['error']['code']
message = result['error']['message']
raise ProtocolError((code, message))
elif type(result['error']) is dict and len(result['error']) == 1:
error_key = result['error'].keys()[0]
raise ProtocolError(result['error'][error_key])
else:
raise ProtocolError(result['error'])
return result

def isbatch(result):
Expand Down