Author

Topic: JSON-RPC validation error (Read 997 times)

legendary
Activity: 1274
Merit: 1006
Trainman
November 19, 2015, 07:46:03 AM
#3
Code:
from jsonrpc import ServiceProxy
 
access = ServiceProxy("http://user:[email protected]:8332")
access.getinfo()

require http://json-rpc.org/wiki/python-json-rpc
hero member
Activity: 521
Merit: 522
Developer - EthicHacker - BTC enthusiast
November 19, 2015, 06:06:57 AM
#2
I'm trying to make connection to my JSON RPC via python script. I've tried several different libraries, the one I got most success gives me that message:
Code:
Traceback (most recent call last):
  File "test_conn_btc.py", line 6, in
    x = server.request('getinfo')
  File "/usr/local/lib/python3.4/dist-packages/jsonrpcclient/server.py", line 98, in request
    return self.handle_response(self.send_message(request), True)
  File "/usr/local/lib/python3.4/dist-packages/jsonrpcclient/server.py", line 133, in handle_response
    json_validator.validate(response_dict)
  File "/usr/local/lib/python3.4/dist-packages/jsonschema/validators.py", line 123, in validate
    raise error
jsonschema.exceptions.ValidationError: 'jsonrpc' is a required property

Failed validating 'required' in schema['allOf'][0]:
    {'properties': {'id': {'oneOf': [{'type': 'string'},
                                     {'type': 'integer'},
                                     {'type': 'null'}]},
                    'jsonrpc': {'enum': ['2.0'], 'type': 'string'}},
     'required': ['jsonrpc', 'id'],
     'type': 'object'}

On instance:
    {'error': None,
     'id': 1,
     'result': {'balance': 1.89,
                'blocks': 598181,
                'connections': 8,
                'difficulty': 7150.92333102,
                'errors': 'WARNING: abnormally high number of blocks '
                          'generated, 11409 blocks received in the last '
                          '4 hours (24 expected)',
                'keypoololdest': 1447081146,
                'keypoolsize': 104,
                'paytxfee': 0.0,
                'protocolversion': 70002,
                'proxy': '',
                'relayfee': 5e-05,
                'testnet': True,
                'timeoffset': -1,
                'version': 110100,
                'walletversion': 60000}}

Here is the code of script:

Code:
from jsonrpcclient.http_server import HTTPServer
import json
# docs at https://jsonrpcclient.readthedocs.org/http.html
server = HTTPServer('http://127.0.0.1:18332', auth=('user', 'password'))

x = server.request('getinfo')
print(x)
What may be the problem?

looks like json validation error. why not use the python library from Peter Todd? You may have a look. Its very mighty and
you can do lots more than only using a standard rpc interface for communication with btc-core.

https://github.com/petertodd/python-bitcoinlib


p.s. jgarzik also has a python-lib for btc. https://github.com/jgarzik/python-bitcoinrpc
member
Activity: 121
Merit: 10
November 10, 2015, 07:08:07 AM
#1
I'm trying to make connection to my JSON RPC via python script. I've tried several different libraries, the one I got most success gives me that message:
Code:
Traceback (most recent call last):
  File "test_conn_btc.py", line 6, in
    x = server.request('getinfo')
  File "/usr/local/lib/python3.4/dist-packages/jsonrpcclient/server.py", line 98, in request
    return self.handle_response(self.send_message(request), True)
  File "/usr/local/lib/python3.4/dist-packages/jsonrpcclient/server.py", line 133, in handle_response
    json_validator.validate(response_dict)
  File "/usr/local/lib/python3.4/dist-packages/jsonschema/validators.py", line 123, in validate
    raise error
jsonschema.exceptions.ValidationError: 'jsonrpc' is a required property

Failed validating 'required' in schema['allOf'][0]:
    {'properties': {'id': {'oneOf': [{'type': 'string'},
                                     {'type': 'integer'},
                                     {'type': 'null'}]},
                    'jsonrpc': {'enum': ['2.0'], 'type': 'string'}},
     'required': ['jsonrpc', 'id'],
     'type': 'object'}

On instance:
    {'error': None,
     'id': 1,
     'result': {'balance': 1.89,
                'blocks': 598181,
                'connections': 8,
                'difficulty': 7150.92333102,
                'errors': 'WARNING: abnormally high number of blocks '
                          'generated, 11409 blocks received in the last '
                          '4 hours (24 expected)',
                'keypoololdest': 1447081146,
                'keypoolsize': 104,
                'paytxfee': 0.0,
                'protocolversion': 70002,
                'proxy': '',
                'relayfee': 5e-05,
                'testnet': True,
                'timeoffset': -1,
                'version': 110100,
                'walletversion': 60000}}

Here is the code of script:

Code:
from jsonrpcclient.http_server import HTTPServer
import json
# docs at https://jsonrpcclient.readthedocs.org/http.html
server = HTTPServer('http://127.0.0.1:18332', auth=('user', 'password'))

x = server.request('getinfo')
print(x)
What may be the problem?
Jump to: