Bitcoin Forum
October 22, 2018, 08:08:33 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: JSON-RPC validation error  (Read 906 times)
Mikolo
Member
**
Offline Offline

Activity: 115
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?
1540238913
Hero Member
*
Offline Offline

Posts: 1540238913

View Profile Personal Message (Offline)

Ignore
1540238913
Reply with quote  #2

1540238913
Report to moderator
1540238913
Hero Member
*
Offline Offline

Posts: 1540238913

View Profile Personal Message (Offline)

Ignore
1540238913
Reply with quote  #2

1540238913
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1540238913
Hero Member
*
Offline Offline

Posts: 1540238913

View Profile Personal Message (Offline)

Ignore
1540238913
Reply with quote  #2

1540238913
Report to moderator
1540238913
Hero Member
*
Offline Offline

Posts: 1540238913

View Profile Personal Message (Offline)

Ignore
1540238913
Reply with quote  #2

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

Activity: 502
Merit: 500


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: 1064
Merit: 1001

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

A smartness bitcoin which will operate as the human brain can easily scale beyond the level of traffic VISA,Trainman pgp
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!