Bitcoin Forum
May 11, 2024, 06:50:01 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: JSON-RPC validation error  (Read 977 times)
Mikolo (OP)
Member
**
Offline Offline

Activity: 121
Merit: 10


View Profile
November 10, 2015, 12:08:07 PM
 #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 <module>
    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?
1715453401
Hero Member
*
Offline Offline

Posts: 1715453401

View Profile Personal Message (Offline)

Ignore
1715453401
Reply with quote  #2

1715453401
Report to moderator
1715453401
Hero Member
*
Offline Offline

Posts: 1715453401

View Profile Personal Message (Offline)

Ignore
1715453401
Reply with quote  #2

1715453401
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715453401
Hero Member
*
Offline Offline

Posts: 1715453401

View Profile Personal Message (Offline)

Ignore
1715453401
Reply with quote  #2

1715453401
Report to moderator
ca333
Hero Member
*****
Offline Offline

Activity: 520
Merit: 522


Developer - EthicHacker - BTC enthusiast


View Profile
November 19, 2015, 11: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 <module>
    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

this space is available (free) for humanitarian nonprofit organizations - please contact me
chrisvl
Legendary
*
Offline Offline

Activity: 1274
Merit: 1006

Trainman


View Profile WWW
November 19, 2015, 12:46:03 PM
 #3

Code:
from jsonrpc import ServiceProxy
 
access = ServiceProxy("http://user:password@127.0.0.1:8332")
access.getinfo()

require http://json-rpc.org/wiki/python-json-rpc

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!